用于多个输入的 JQuery 日期选择器函数 [英] JQuery datepicker function for multiple from inputs

查看:43
本文介绍了用于多个输入的 JQuery 日期选择器函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 jquery 的日期选择器用于我在硬编码时工作的多个表单字段.我不知道如何对可变数量的字段执行此操作.例如,下面我对其进行了硬编码以适用于两个输入.我想对用户在上一页上提供的任意数量的输入执行此操作.谢谢您的帮助!

I'm trying to use jquery's datepicker for multiple form fields which I have working when hard coded. I don't know how to do this for a variable number of fields. For example, below I have hard coded it to work for two inputs. I want to do this for any amount of inputs the user provides on a previous page. Thanks for the help!

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

推荐答案

使用通用类或将名称与属性选择器一起使用

Use a common class or use the name with an attribute selector

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

这篇关于用于多个输入的 JQuery 日期选择器函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆