简体   繁体   English

将datepicker分配给输入字段数组

[英]Assigning datepicker to array of input fields

i've looked around the internet but can't seem to find what i need. 我环顾了互联网,但似乎找不到我需要的东西。

I have an input field called date[] with class 'datepicker', i then have a function to clone these input fields using jquery, so i can have multiple fields 我有一个名为date []且类为'datepicker'的输入字段,然后有一个函数使用jquery克隆这些输入字段,因此我可以有多个字段

$(".datepicker").datepicker({dateFormat: 'dd-mm-yy', minDate: 0});

<input type="text" name="date[]" value="" class="datepicker" />

When there is one input field on the page, it works fine, when there are 2, they are both populated with the same value, the picker doesnt show on the first when you click it, but it does on the second, however the value doesnt get changed when it should. 当页面上有一个输入字段时,它工作正常,当有2个输入字段时,它们都填充有相同的值,当您单击它时,选择器不会在第一个显示,但在第二个显示,但是该值不会在应该的时候改变。

Any ideas how to get this working 任何想法如何使这个工作

EDIT: 编辑:

After playing around a bit more, this code does work for multiple fields, but only when they are static. 在多玩了几遍之后,此代码确实适用于多个字段,但仅当它们是静态的时才适用。 My input fields are generated dynamically using .clone() and .prependTo(), this is when the problems start. 我的输入字段是使用.clone()和.prependTo()动态生成的,这是问题开始的时候。 Any ideas? 有任何想法吗?

in the line $(".datepicker").datepicker({dateFormat: 'dd-mm-yy', minDate: 0}); $(".datepicker").datepicker({dateFormat: 'dd-mm-yy', minDate: 0}); , .datepicker is like an argument to datepicker indicating where to put returned values. .datepicker类似于.datepicker的参数,指示将返回值放在何处。 And it should be unique. 而且应该是唯一的。 If you use more than one element having class as datepicker , datepicker function will return same value to both. 如果您使用多个类作为datepicker元素,则datepicker函数将为两个返回相同的值。 Instead you can use something like - 相反,您可以使用类似-

$("#datepicker1,#datepicker2").datepicker({dateFormat: 'dd-mm-yy', minDate: 0});​ and html is - ​Demo $("#datepicker1,#datepicker2").datepicker({dateFormat: 'dd-mm-yy', minDate: 0});​和HTML是- 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM