datepicker won't fire an onchange event

霸气de小男生 提交于 2020-01-11 07:21:27

问题


I have two input date field, one generates a date through JQuery datepicker, I wanr the second to take the value from the first input via onblur or onchange event, it works fine when I enter the date manually, but once entered through the datepicker, it won't fire the second input

here is my Jquery code:

 <script type="text/javascript">
  $(function () {
  var duration=0;
  $('#date1').datepicker({ minDate: +1,onSelect: function(selectedDate) {


        var date = $(this).datepicker('getDate');

        date.setDate(date.getDate() + parseInt(duration)); // Add 7 days


      }});

  });

  </script>

and here is the html code for the inputs:

   <input name="date1" type="text" id="date1"          onchange="document.zipad.date1_end.value=document.zipad.date1.value"  />
  </div>
    <div id="warning_moderation"></div></td>
  <div id="mydate"></div>
  <td><div id="warning1">Please allow 24 Hours for moderation before your ads will be published</div></td>
</tr>
<tr>
  <td height="44">Ending Date:<br/>
    <input  name="date1_end" type="text" id="date1_end" disabled="disabled"/>

回答1:


$('#date1').datepicker({ minDate: +1,onSelect: function(selectedDate) {


    var date = $(this).datepicker('getDate');

    date.setDate(date.getDate() + parseInt(duration)); // Add 7 days

    $('#date1').trigger('change');
  }});


来源:https://stackoverflow.com/questions/19149092/datepicker-wont-fire-an-onchange-event

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