我想使用jquery删除父div中12 div之后的所有div。 标记就像:
<div id="dvNames" class="container grayBox float-left">
<div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_30" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_31" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_32" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_33" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_34" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_35" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_36" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_37" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_38" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_39" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_40" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_41" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_42" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_43" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_44" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_45" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_46" type="text"></div><br></div><div class="float-left margin-bottom-10 width-33-per divContainer"><div class="float-left"><input placeholder="LastName,FirstName" onchange="CheckVisitorName(this)" class="width-180 reset" name="name_47" type="text"></div><br></div>
</div>
我知道我们可以像$('#dvNames div')
这样在父div中获取所有div。删除像$('#dvNames div').remove()
删除所有div。我们也可以通过$('#dvNames div:first')
得到每一个。
所以我最终得到了
for(;$('#dvNames div').length>12;) $('#dvNames div:first').remove()
我的意图是有效的,但我觉得必须有一些方法没有循环。
如果你知道没有循环的方法,请帮助我。