JQuery Daterangepicker onchange event

2019-08-19 00:30发布

All the answers I could find are for Datepicker and it doesn't work the same!

It only fires an onChange() event if I modify the value with the keyboard and not the bootstrap interface.

I've tested everything showed here

My code:

JAVASCRIPT

            $(function () {
                //Date range picker
                $('#reservation').daterangepicker({
                    onSelect: function() {
                        $(this).change();
                    }                    
                });
            });

            $(document).ready(function () {
                $("#reservation").change(function () {
                    var date = $("#reservation").val();
                    var replaced = date.split(' ').join('')
                    $("#partialtable").load('@(Url.Action("GetDateResults", "Temps", null, Request.Url.Scheme))?date=' + replaced);
                });
            });

HTML

<!-- Date range -->
            <div class="form-group">
                <label>Période:</label>
                <div class="input-group">
                    <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>
                    </div>
                    <input type="text" class="form-control pull-right" id="reservation" onchange=""/>
                </div><!-- /.input group -->
            </div><!-- /.form group --> 

Anyone can find a solution please? I don't mind to trigger the event even if the change is the same value as before!

1条回答
beautiful°
2楼-- · 2019-08-19 00:55

You can try with this:

<script type="text/javascript">
   $(function() {
      $('#reservation').daterangepicker({
         //singleDatePicker: true,
         //showDropdowns: true
      }, 
     function() {
        var date = $("#reservation").val();
        var replaced = date.split(' ').join('')
        $("#partialtable").load('@(Url.Action("GetDateResults", "Temps", null, Request.Url.Scheme))?date=' + replaced);
    });
  });
</script>

I hope it will work for you!!

查看更多
登录 后发表回答