JQuery Daterangepicker onchange event

白昼怎懂夜的黑 提交于 2019-12-12 05:31:46

问题


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:


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!!




回答2:


<script type="text/javascript">
   $(function() {
      $('#reservation').daterangepicker({
         //singleDatePicker: true,
         //showDropdowns: true
      }, 
     function() {
        let date = $(".drp-selected").text()
        console.log(date)
    });
  });
</script>


来源:https://stackoverflow.com/questions/44553261/jquery-daterangepicker-onchange-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!