【问题标题】:JQuery datepicker function for multiple from inputs用于多个输入的 JQuery datepicker 函数
【发布时间】:2013-12-11 20:56:55
【问题描述】:

我正在尝试将 jquery 的 datepicker 用于我在硬编码时工作的多个表单字段。我不知道如何为可变数量的字段执行此操作。例如,下面我将它硬编码为适用于两个输入。我想对用户在前一页提供的任何数量的输入执行此操作。谢谢您的帮助!

 <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
      <script src="https://www.cvrc.virginia.edu/otherscripts/jquery-1.9.1.js"></script>
      <script src="https://www.cvrc.virginia.edu/otherscripts/jquery-ui.js"></script>
      <script>
      $(function() {
        $( "#datepicker" ).datepicker();
      });
      $(function() {
        $( "#datepicker2" ).datepicker();
      });
      </script>

      <input type=text name=date size=10 id=datepicker>
      <input type=text name=date size=10 id=datepicker2>

【问题讨论】:

    标签: javascript jquery html forms datepicker


    【解决方案1】:

    使用通用类或使用属性选择器的名称

    JavaScript

    $('[name="date"]').datepicker();
    

    $(".datepicker").datepicker();
    

    HTML 如果你使用类选择器

     <input type="text" name="date" size="10" id="datepicker" class="datepicker">
     <input type="text" name="date" size="10" id="datepicker2" class="datepicker">
    

    【讨论】:

    • 他们有相同的名字吗?
    猜你喜欢
    • 2012-06-03
    • 1970-01-01
    • 1970-01-01
    • 2015-07-18
    • 1970-01-01
    • 1970-01-01
    • 2018-04-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多