简体   繁体   English

jQuery:查找除特定父类的复选框以外的输入字段

[英]jQuery: Find input fields except checkbox with a particular parent class

Trying this multiselect bootstrap plug in which shows options as check-box. 尝试使用多选引导插件,其中显示选项作为复选框。 在此输入图像描述

Problem is when I try to all the input fields, it goes all those checkboxes too. 问题是,当我尝试所有输入字段时,它也会查看所有这些复选框。 I want to avoid these option checkboxes. 我想避免使用这些选项复选框。
That's how they look in HTML 这就是他们在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>

Current code is 目前的代码是

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

How can I filter only those checkboxes which has a parent <label class="checkbox"> ? 如何仅筛选具有父<label class="checkbox">

Is this what you want? 这是你想要的吗?

$(section).find('input:not(:checkbox), select').filter(function(){
    return !$(this).parent().children('.checkbox')[0];
}).each(function(i, field) {
   //your code here 
});

You can just make your selector: 你可以做你的选择器:

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

That will include any <input> element that isn't inside a <label class="checkbox"> element and of type checkbox , as well as all <select> elements. 这将包括不在<label class="checkbox">元素和类型checkbox内的任何<input>元素,以及所有<select>元素。

Your code would become: 您的代码将变为:

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

    function( i, field ) {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM