Javascript 一页上有多个日期选择器,每个日期选择器具有动态ID';s
我正在使用一个表单克隆插件(),它克隆表单元素,在我的例子中,每个表单都包含一个jQuery日期选择器 在“普通”表单中,我将日期选择器附加到类中,即使在一个页面上有多个日期选择器,它也可以工作,但由于我不知道表单上可能有多少项,因此不知道如何将其添加到ID中 当我尝试使用SheepIt克隆时,我得到一个错误:Javascript 一页上有多个日期选择器,每个日期选择器具有动态ID';s,javascript,jquery,datepicker,Javascript,Jquery,Datepicker,我正在使用一个表单克隆插件(),它克隆表单元素,在我的例子中,每个表单都包含一个jQuery日期选择器 在“普通”表单中,我将日期选择器附加到类中,即使在一个页面上有多个日期选择器,它也可以工作,但由于我不知道表单上可能有多少项,因此不知道如何将其添加到ID中 当我尝试使用SheepIt克隆时,我得到一个错误: Uncaught Missing instance data for this datepicker 示例(我模拟了三个文本框,但可能有一个,也可能有二十个): 牧羊犬代码: <
Uncaught Missing instance data for this datepicker
示例(我模拟了三个文本框,但可能有一个,也可能有二十个):
牧羊犬代码:
<script type="text/javascript">
$(document).ready(function() {
var sheepItForm = $('#sheepItForm').sheepIt({
separator: '',
allowRemoveLast: true,
allowRemoveCurrent: true,
allowRemoveAll: true,
allowAdd: true,
allowAddN: true,
maxFormsCount: 50,
minFormsCount: 0,
iniFormsCount: 1,
removeLastConfirmation: true,
removeCurrentConfirmation: true,
removeAllConfirmation: true,
removeLastConfirmationMsg: 'Are you sure? This will remove the last added item',
removeCurrentConfirmationMsg: 'Are you sure? This will remove this item',
removeAllConfirmationMsg: 'Are you sure? This will remove all items'
});
});
</script>
$(文档).ready(函数(){
var sheepItForm=$(“#sheepItForm”)。绵羊({
分隔符:“”,
allowRemoveLast:对,
allowRemoveCurrent:正确,
是的,
阿洛瓦德:是的,
阿洛瓦顿:是的,
maxFormsCount:50,
minFormsCount:0,
答案:1,
removeLastConfirmation:正确,
RemoveCurrent确认:true,
removeAllConfirmation:正确,
removeLastConfirmationMsg:'您确定吗?这将删除最后添加的项目',
removeCurrentConfirmationMsg:'您确定吗?这将删除此项目',
removeAllConfirmationMsg:'您确定吗?这将删除所有项目'
});
});
当数量(因此ID)未知时,如何让日期选择器在任何日期选择器框上工作
谢谢添加克隆表单后,SheepIt会回调(
afterAdd
)。您可以在此处初始化日期选择器:
var sheepItForm = $('#sheepItForm').sheepIt({
separator: '',
allowRemoveLast: true,
allowRemoveCurrent: true,
allowRemoveAll: true,
allowAdd: true,
allowAddN: true,
maxFormsCount: 50,
minFormsCount: 0,
iniFormsCount: 1,
removeLastConfirmation: true,
removeCurrentConfirmation: true,
removeAllConfirmation: true,
removeLastConfirmationMsg: 'Are you sure? This will remove the last added item',
removeCurrentConfirmationMsg: 'Are you sure? This will remove this item',
removeAllConfirmationMsg: 'Are you sure? This will remove all items',
// Callback - initialise datepicker
afterAdd: function(source, newForm) {
$(".datepicker").datepicker({
firstDay: 1,
dateFormat: "dd/mm/yy"
});
}
});
他已经开始工作了。您只需要包括jQueryUI库(在JSFIDLE的左侧菜单上)。如果可能的话,我建议不要使用
id
!很抱歉,当SheepIt代码克隆表单元素时,它不能“实时”工作-我试图避免为JSFIDLE设置SheepIt以使其更简单,但我失败了!你为什么还要身份证?您可以使用this
访问内容,并根据SheepIt脚本使用ID进行遍历,因此我假设它需要它们-我通常不会将ID用于带有日期选择器的正常表单项-我必须在这两种情况下使用beforeAdd和afterAdd与初始化代码一起使用,但现在可以使用了
<script type="text/javascript">
$(document).ready(function() {
var sheepItForm = $('#sheepItForm').sheepIt({
separator: '',
allowRemoveLast: true,
allowRemoveCurrent: true,
allowRemoveAll: true,
allowAdd: true,
allowAddN: true,
maxFormsCount: 50,
minFormsCount: 0,
iniFormsCount: 1,
removeLastConfirmation: true,
removeCurrentConfirmation: true,
removeAllConfirmation: true,
removeLastConfirmationMsg: 'Are you sure? This will remove the last added item',
removeCurrentConfirmationMsg: 'Are you sure? This will remove this item',
removeAllConfirmationMsg: 'Are you sure? This will remove all items'
});
});
</script>
var sheepItForm = $('#sheepItForm').sheepIt({
separator: '',
allowRemoveLast: true,
allowRemoveCurrent: true,
allowRemoveAll: true,
allowAdd: true,
allowAddN: true,
maxFormsCount: 50,
minFormsCount: 0,
iniFormsCount: 1,
removeLastConfirmation: true,
removeCurrentConfirmation: true,
removeAllConfirmation: true,
removeLastConfirmationMsg: 'Are you sure? This will remove the last added item',
removeCurrentConfirmationMsg: 'Are you sure? This will remove this item',
removeAllConfirmationMsg: 'Are you sure? This will remove all items',
// Callback - initialise datepicker
afterAdd: function(source, newForm) {
$(".datepicker").datepicker({
firstDay: 1,
dateFormat: "dd/mm/yy"
});
}
});