javascript - jQuery:查找除具有特定父类的复选框之外的输入字段

标签 javascript jquery twitter-bootstrap

尝试这个多选 Bootstrap 插件,其中将选项显示为复选框。 enter image description here

问题是当我尝试所有输入字段时,它也会出现所有这些复选框。我想避免使用这些选项复选框。
这就是它们在 HTML 中的外观

<li>
<a href="javascript:void(0);">
<label class="checkbox">
<input type="checkbox" value="2"> Options 2</label>
</a>
</li>
<li>
<a href="javascript:void(0);">
<label class="checkbox">
<input type="checkbox" value="3"> Options 3</label>
</a>
</li>

当前代码是

$(section).find('input:not(:checkbox), select').each(function(i, field) {

如何仅过滤那些具有父项 <label class="checkbox"> 的复选框?

最佳答案

您可以创建选择器:

input:not(label.checkbox :checkbox), select

这将包括任何 <input>不在 <label class="checkbox"> 内的元素元素和类型 checkbox ,以及所有 <select>元素。

您的代码将变为:

$(section).find('input:not(label.checkbox :checkbox), select').each(function(i, field) {

关于javascript - jQuery:查找除具有特定父类的复选框之外的输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19096674/

相关文章:

javascript - 在单个页面中引入多个加载器: React JS

javascript - 在应用程序中的任何位置调用辅助函数 - Node/Express

javascript - 如何绑定(bind)到模糊和更改,但只在 Jquery/Javascript 中触发一次函数?

javascript - 使用 Browser Profile Enterprise 设置时 IE11 的 Twitter Bootstrap 问题

javascript - 将响应式背景图像添加到部门类 Bootstrap

javascript - 谷歌客户端 api 在 iphone 中不工作(safari 浏览器)

javascript - node.js - cron.js 与 setInterval

php - 使用 jQuery .load() 从输入加载数组到 PHP?

javascript - 循环遍历仅以特定模式开头的 JSON 对象

html - Bootstrap 导航栏 : Width of left element affects position of element in the center