<input type="text" class="incorrect">
<input type="text" class="correct">
<input type="text" class="defalut">
<input type="text" class="correct">
<input type="text" class="incorrect">
<input type="text" class="">
我正在使用 jquery 。 我的意思是,现在我专注于第一个输入(其类别为不正确)。我想获得既没有 class=default 也没有 class= Correct 的下一个输入。如何实现呢? 我尝试一下
input:not(.correct):not(.defalut)
或
input:not(.correct .defalut)
但似乎不起作用! 非常感谢!
最佳答案
使用逗号分隔类名。如果您希望焦点集中在第一个元素以外的元素上,并且没有类“正确”或“默认”,请使用以下内容。这里我使用了filter()
功能和slice()
函数不选择第一个元素。
这里
var count = $('input:not(.correct, .defalut)').length;
alert( "Number of inputs not have classnames 'correct' or 'defalut' : " + count );
$('input').slice(1).filter(':not(.correct, .defalut)').first().focus();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="incorrect">
<input type="text" class="correct">
<input type="text" class="defalut">
<input type="text" class="correct">
<input type="text" class="incorrect">
<input type="text" class="">
关于javascript - jquery选择器使用 'not:'两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34128354/