<fieldset id="tt">
<div class="cts">
<div class="tbox">
<input type="text" class="pp"/>
</div>
</div>
<div class="cts">
<div class="tarea">
<input type="text">
</div>
</div>
<div class="cts">
<div class="tbox">
<input type="text" class="pp"/>
</div>
</div>
<div class="cts">
<div class="tarea">
<input type="text">
</div>
</div>
</fieldset>
$('.cts').find('div:first').each(function(i){
var attr = $(this).attr('class');
alert(attr)
switch(attr) {
case "tbox":
$('<div class="fieldProperties"> <input type="text" value="first" name="fields['+i+'].id" id="fields['+i+'].id"> </div>')
.insertAfter($('.cts').find('div.tbox'));
break;
case "tarea":
$('<div class="fieldProperties"> <input type="text" value="second" name="fields['+i+'].id" id="fields['+i+'].id"></div>')
.insertAfter($('.cts').find('div.tarea'));
break;
}
});
在这里,我试图在插入最新的<div class="properties">
之后插入<div class="tbox">
,但在这里插入每个 div。每次都会加载一些字段属性<div class="tarea">
<div class="properties">
我正在低于 DOM 结构,但我不想这样
<fieldset id="tt">
<div class="cts">
<div class="tbox">
<input type="text" class="pp">
</div><div class="fieldProperties"><input type="text" id="fields[2].id" name="fields[2].id" value="first"></div><div class="fieldProperties"><input type="text" id="fields[0].id" name="fields[0].id" value="first"></div>
</div>
<div class="cts">
<div class="tarea">
<input type="hidden">
</div><div class="fieldProperties"><input type="text" id="fields[3].id" name="fields[3].id" value="first"></div><div class="fieldProperties"><input type="text" id="fields[1].id" name="fields[1].id" value="first"></div>
</div>
<div class="cts">
<div class="tbox">
<input type="text" class="pp">
</div><div class="fieldProperties"><input type="text" id="fields[2].id" name="fields[2].id" value="first"></div><div class="fieldProperties"><input type="text" id="fields[0].id" name="fields[0].id" value="first"></div>
</div>
<div class="cts">
<div class="tarea">
<input type="hidden">
</div><div class="fieldProperties"><input type="text" id="fields[3].id" name="fields[3].id" value="first"></div><div class="fieldProperties"><input type="text" id="fields[1].id" name="fields[1].id" value="first"></div>
</div>
</fieldset>
我正在尝试使用dom结构
<fieldset id="tt">
<div class="cts">
<div class="tbox">
<input type="text" class="pp">
</div><div class="fieldProperties"><input type="text" id="fields[0].id" name="fields[0].id" value="first"></div>
</div>
<div class="cts">
<div class="tarea">
<input type="hidden">
</div><div class="fieldProperties"><input type="text" id="fields[1].id" name="fields[1].id" value="first"></div>
</div>
<div class="cts">
<div class="tbox">
<input type="text" class="pp">
</div><div class="fieldProperties"><input type="text" id="fields[2].id" name="fields[2].id" value="first"></div>
</div>
<div class="cts">
<div class="tarea">
<input type="hidden">
</div><div class="fieldProperties"><input type="text" id="fields[3].id" name="fields[3].id" value="first"></div>
</div>
</fieldset>