jQuery Datepicker for multiple inputs

前端 未结 8 1755
忘了有多久
忘了有多久 2021-01-04 16:47

I have a jQuery datepicker script:

$(function() {
    $( \"#datepicker\" ).datepicker({ dateFormat: \"yyyy-mm-dd\" });         


        
相关标签:
8条回答
  • 2021-01-04 17:08
      <script>
      $(document).ready(function() {
        $("#datepicker").datepicker();
      });
      $(document).ready(function() {
        $("#datepicker2").datepicker();
      });
      $(document).ready(function() {
        $("#datepicker3").datepicker();
      });
      </script>
    

    And just give the forms the id's: datepicker datepicker2 datepicker3

    0 讨论(0)
  • 2021-01-04 17:11

    It isn't valid to have duplicated IDs. You should add a class instead:

    <input type="text" name="MyDate1" class="datepicker" id="datepicker1">
    <input type="text" name="MyDate2" class="datepicker" id="datepicker2">
    

    Then you can do:

    $(function() {
        $( ".datepicker" ).datepicker({ dateFormat: "yyyy-mm-dd" });
    }); 
    
    0 讨论(0)
提交回复
热议问题