jquery 如果 div 不是 id
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5804009/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery if div not id
提问by tonoslfx
I want to cut the price off to all input value in all divs, except only one div sale_wrap
. how do I make an exception with jquery?
我想将价格降低到所有 div 中的所有输入值,只有一个div sale_wrap
. 我如何对 jquery 进行例外处理?
<div id="one_wrap">
<input type="checkbox" name="1" value="">
<input type="checkbox" name="1" value="">
</div>
<div id="two_wrap">
<input type="checkbox" name="2" value="">
<input type="checkbox" name="2" value="">
</div>
<div id="sale_wrap">
<input type="checkbox" name="3" value="">
</div>
jquery:
查询:
if($("div").attr("id") != "sale_wrap") {
t_balance;
} else {
var sale = t_balance*((100-window.discount_p)/100);
t_balance = sale;
}
回答by z33m
回答by Chris Lawlor
The jQuery not()
function can do this.
jQuerynot()
函数可以做到这一点。
To select all div's except the div with id
of sale_wrap
:
要选择所有的div除与DIVid
的sale_wrap
:
$('div').not('#sale_wrap')
You can then loop over the divs with each()
.
然后,您可以使用each()
.
As an example:
举个例子:
#HTML
<p id="1">Some text in paragraph 1</p>
<p id="2">Some text in paragraph 2</p>
<p id="3">Some text in paragraph 3</p>
#JS
# turn background to blue for all 'p' except p with id=2
$('p').not('#2').each(function() {
$(this).css('background-color', 'blue');
});
Check out this example on JsFiddle.
回答by Deviprasad Das
Try using
尝试使用
if($('div').not('#sale_wrap'))
{
t_balance;
}
else
{
var sale = t_balance*((100-window.discount_p)/100);
t_balance = sale;
}
回答by Om Sao
Just to add little more information. One can use multiple not selectorlike this:
只是为了添加更多信息。可以像这样使用多个not 选择器:
$("div:not(#sale_wrap):not(.sale_class)");
or
或者
$("div:not(#sale_wrap, .sale_class)");
or
或者
$("div").not('#sale_wrap, .sale_class');
回答by sh54
Alternatively:
或者:
$('div[id != "sale_wrap"]')