gpt4 book ai didi

php - 动态输入字段上的 jquery datepicker

转载 作者:行者123 更新时间:2023-12-01 02:31:36 24 4
gpt4 key购买 nike

我需要有关动态创建的输入字段的日期选择器的帮助...

我有这个表格:

    <table id="reminder">
<tr>
<th>Payment Reminders</th>
<th></th>
<th></th>
<th></th>
</tr>
<tr>
<td><label>Reminder</label></td>
<td><input type="text" name="payreminder[]" id="payreminder" class="input1" size="20" ><script>$('#payreminder').datepicker({dateFormat: $.datepicker.W3C, changeMonth: true, changeYear: true, yearRange: '2011:2020'}); </script></td>
<td><label>Description</label></td>
<td><input type="text" class="input1" name="paydescription[]" id="paydescription"></td>
<td> <a href="#" onClick="addReminder('dynamicInputReminder');" title="Add another">Add another</a></td>
</tr>
<tr>
<td colspan="6"><div id="dynamicInputReminder"></div> </td>

</tr>


</table>

添加更多提醒的 JavaScript 是:

<script type="text/javascript" >

var counterReminder = 1;
var limit = 20;
function addReminder(divName){
if (counterReminder == limit) {
alert("You have reached the limit of adding " + counterReminder+ " inputs");
}
else {
var newdiv = document.createElement('div');
newdiv.innerHTML = "<td><label>Reminder</label></td><td><input type=\"text\" id=\"payreminder["+counterReminder+"]\" name=\"payreminder["+counterReminder+"]\" class=\"input1\" ></td><td><label>Description</label></td><td><input type=\"text\" id=\"paydescription["+counterReminder+"]\" name=\"paydescription["+counterReminder+"]\" class=\"input1\"></td>";
document.getElementById(divName).appendChild(newdiv);
counterReminder++;
}
}
</script>

问题是:如何以及在哪里调用日期选择器的下面的脚本,以便它适用于动态创建的字段?

<script>$('#payreminder').datepicker({dateFormat: $.datepicker.W3C, changeMonth: true, changeYear: true, yearRange: '2011:2020'}); </script>

非常感谢!

最佳答案

例如,在输入字段中使用类而不是 ID

<input type=\"text\"  id=\"payreminder["+counterReminder+"]\" name=\"payreminder["+counterReminder+"]\" class=\"payreminder\" >

<script>
$(document).on('focusin', '.payreminder', function(){
$(this).datepicker({dateFormat: $.datepicker.W3C, changeMonth: true, changeYear: true, yearRange: '2011:2020'});
});
</script>

关于php - 动态输入字段上的 jquery datepicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15155204/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com