Javascript 对一组元素css选择器应用:not的方法?
给定一组输入:Javascript 对一组元素css选择器应用:not的方法?,javascript,jquery,html,css,selector,Javascript,Jquery,Html,Css,Selector,给定一组输入: <div id="group"> <input id="uno" class="red"></input><br/> <input id="dos" class="red"></input><br/> <input id="tres" class="blue"></input><br/> <textarea id=
<div id="group">
<input id="uno" class="red"></input><br/>
<input id="dos" class="red"></input><br/>
<input id="tres" class="blue"></input><br/>
<textarea id="a1" class="blue"></textarea><br/>
<textarea id="a2" class="red"></textarea><br/>
</div>
我想做一些类似于”(输入,textarea):不是(.blue)
,但这不起作用。是否有方法对一组元素选择器应用:not
这里有一个起点:当您使用多个选择器时,其中的每个选择器都应该是完整的
$('#group').on('keypress', 'input:not(.blue),textarea:not(.blue)', function(e){
$(e.target).css('background-color', 'lightgreen');
});
$('#group')。在('keypress','input:not(.blue),text区域:not(.blue'),函数(e){
$(e.target).css('background-color','lightgreen');
});代码>
当您使用多个选择器时,其中的每个选择器都应完整
$('#group').on('keypress', 'input:not(.blue),textarea:not(.blue)', function(e){
$(e.target).css('background-color', 'lightgreen');
});
$('#group')。在('keypress','input:not(.blue),text区域:not(.blue'),函数(e){
$(e.target).css('background-color','lightgreen');
});代码>
当您使用多个选择器时,其中的每个选择器都应完整
$('#group').on('keypress', 'input:not(.blue),textarea:not(.blue)', function(e){
$(e.target).css('background-color', 'lightgreen');
});
$('#group')。在('keypress','input:not(.blue),text区域:not(.blue'),函数(e){
$(e.target).css('background-color','lightgreen');
});代码>
当您使用多个选择器时,其中的每个选择器都应完整
$('#group').on('keypress', 'input:not(.blue),textarea:not(.blue)', function(e){
$(e.target).css('background-color', 'lightgreen');
});
$('#group')。在('keypress','input:not(.blue),text区域:not(.blue'),函数(e){
$(e.target).css('background-color','lightgreen');
});代码>
我不认为将:not
添加到一个组中是可能的,一个正确的方法和解决方案是如下所示:
$('#group').on('keypress', 'input:not(.blue),textarea:not(.blue)', function(e){
$(e.target).css('background-color', 'lightgreen');
});
我不认为将:not
添加到组中是可能的,一种正确的方法和解决方案是如下所示:
$('#group').on('keypress', 'input:not(.blue),textarea:not(.blue)', function(e){
$(e.target).css('background-color', 'lightgreen');
});
我不认为将:not
添加到组中是可能的,一种正确的方法和解决方案是如下所示:
$('#group').on('keypress', 'input:not(.blue),textarea:not(.blue)', function(e){
$(e.target).css('background-color', 'lightgreen');
});
我不认为将:not
添加到组中是可能的,一种正确的方法和解决方案是如下所示:
$('#group').on('keypress', 'input:not(.blue),textarea:not(.blue)', function(e){
$(e.target).css('background-color', 'lightgreen');
});
或者你可以这样做
$('#group input,textarea').not(".blue").on('keypress', function(e){
$(e.target).css('background-color', 'lightgreen');
});
或者你可以这样做
$('#group input,textarea').not(".blue").on('keypress', function(e){
$(e.target).css('background-color', 'lightgreen');
});
或者你可以这样做
$('#group input,textarea').not(".blue").on('keypress', function(e){
$(e.target).css('background-color', 'lightgreen');
});
或者你可以这样做
$('#group input,textarea').not(".blue").on('keypress', function(e){
$(e.target).css('background-color', 'lightgreen');
});
很抱歉,我没有提到我知道关于'input:not(.blue)、textarea:not(.blue)
的信息,也没有指定我想将参数传递给承载.on('keypress')
的函数,该函数带有一个exclude
选择器参数,该参数可以在单个位置使用(因为我可能使用的不仅仅是input
和textarea
元素)因此,虽然@Arun P Johny和@taxicala的答案都很好,但我选择@gerald89的答案是因为它能够将单个排除应用到组中。谢谢大家!很抱歉我没有提到我知道输入:不(.blue),文本区域:不(.blue)“
并没有指定我想将参数传递给承载('keypress')
的函数,该函数带有一个可在单个位置使用的排除选择器参数(因为我可能使用的不仅仅是输入
和文本区域
元素)因此,虽然@Arun P Johny和@taxicala的答案都很好,但我选择@gerald89的答案是因为它能够将单个排除应用到组中。谢谢大家!很抱歉我没有提到我知道输入:不(.blue),文本区域:不(.blue)“
并没有指定我想将参数传递给承载('keypress')
的函数,该函数带有一个可在单个位置使用的排除选择器参数(因为我可能使用的不仅仅是输入
和文本区域
元素)因此,虽然@Arun P Johny和@taxicala的答案都很好,但我选择@gerald89的答案是因为它能够将单个排除应用到组中。谢谢大家!很抱歉我没有提到我知道输入:不(.blue),文本区域:不(.blue)“
并没有指定我想将参数传递给承载('keypress')
的函数,该函数带有一个可在单个位置使用的排除选择器参数(因为我可能使用的不仅仅是输入
和文本区域
元素).所以,虽然@Arun P Johny和@taxicala的答案都很好,但我选择@gerald89的答案是因为它能够将单个排除应用于小组。谢谢大家!