Javascript 结合last和form元素的jquery动态子选择 更新
整理了正在进行的解决方案并添加了一些额外的细节 我有一个基于模板创建克隆的表单区域。为了确保表单按顺序传输,脚本在发送时遍历表单,并附加一个定义当前批处理集的数字。下面是对正在发生的事情的过于简化的描述:Javascript 结合last和form元素的jquery动态子选择 更新,javascript,jquery,forms,selector,Javascript,Jquery,Forms,Selector,整理了正在进行的解决方案并添加了一些额外的细节 我有一个基于模板创建克隆的表单区域。为了确保表单按顺序传输,脚本在发送时遍历表单,并附加一个定义当前批处理集的数字。下面是对正在发生的事情的过于简化的描述: <form> <div class="batch-template"> <div class="batch-piece"> <a class="clone" /> <i
<form>
<div class="batch-template">
<div class="batch-piece">
<a class="clone" />
<input name="test-input">
<input name="another-test-input">
<select name="a-drop-down">
</div>
</div>
<div class="batch-paste-area">
</div>
</form>
令人沮丧的是,我实际上提前尝试了正确的解决方案,但当时忘记了使用逗号
var intCount = 1;
$('.batch-paste-area .batch-piece').each(function(){
/*
* Would like to be able to loop through form fields here
* Below is an attempt to select all form fields for current set
*/
$(this).find("input, select").each(function() {
var strName = $(this).attr('name') + intCount;
$(this).attr('name', strName);
});
intCount++;
});
我建议您不要对多个id属性使用相同的值。。。我真的不明白你的问题,我们不知道什么是“#批处理区域-”+params.strBatchFocus。我经常在jQuery中使用模型复制,我知道有一些困难(比如小部件和事件的复制),但我不理解您在这里的意思。
<form>
<div class="batch-template">
</div>
<div class="batch-paste-area">
<div class="batch-piece">
<a class="clone" />
<input name="test-input1">
<input name="another-test-input1">
<select name="a-drop-down1">
</div>
<div class="batch-piece">
<a class="clone" />
<input name="test-input2">
<input name="another-test-input2">
<select name="a-drop-down2">
</div>
</div>
</form>
var intCount = 1;
$('.batch-paste-area .batch-piece').each(function(){
/*
* Would like to be able to loop through form fields here
* Below is an attempt to select all form fields for current set
*/
$(this + ' input, '+ this + ' select').each(function() {
var strName = $(this).attr('name') + intCount;
$(this).attr('name', strName);
});
intCount++;
});
var intCount = 1;
$('.batch-paste-area .batch-piece').each(function(){
/*
* Would like to be able to loop through form fields here
* Below is an attempt to select all form fields for current set
*/
$(this).find("input, select").each(function() {
var strName = $(this).attr('name') + intCount;
$(this).attr('name', strName);
});
intCount++;
});