我有以下表格:
<div class="container">
<div clas="row">
<form>
<div id="name">
<input class="form-control" name="user_name" value="John Doe" id="user_name">
</div>
<div class="check">
<label for="priority">Priority</label>
<input type="checkbox" name="priority" id="priority" value="1"/>
</div>
<div class="check">
<label for="can-wait">Can Wait</label>
<input type="checkbox" name="can-wait" id="can-wait" value="1"/>
</div>
<div class="check">
<label for="when-possible">When Possible</label>
<input type="checkbox" name="when-possible" id="when-possible" value="1"/>
</div>
<ol id="check-list" >
<li><input type="text" name="taskdesc" value="" class="form-control"/></li>
<li><input type="text" name="tododesc" value="" class="form-control"/></li>
<li><input type="text" name="donedesc" value="" class="form-control"/></li>
</ol>
</form>
</div>
</div>
我需要一个包含容器中第一个div的jQuery对象,第二个div中的所有复选框以及有序列表中的输入。 我试图通过元素迭代迭代并检索我需要的元素,但代码是乱的而且不易读。
我正在寻找一条龙的快捷方式。 有可能吗?
答案 0 :(得分:0)
这几乎就是我所寻找的,但我也要求获得第一个div,所以我改变了你的捷径,我来到了这里:
var controls = $( "div#name, div.check, ol#check-list li > input[name$='desc']" )
答案 1 :(得分:0)
如果你只需要容器div和输入:
var jq = $('.container').clone().html($('.container :checkbox, .container #check-list input'));