JQuery选择器使用:不

时间:2014-08-30 16:16:42

标签: jquery jquery-selectors

我想使用JQuery选择器来选择表单中的所有内容,除了具有certatin css类的元素(及其子项

我尝试使用:不是选择器,但未成功:

$("form:not(.do-not-select)").css("color","red");

http://jsfiddle.net/u001b2gj/

你可以帮帮我吗?

1 个答案:

答案 0 :(得分:2)

您可以使用:

$("form :not(.do-not-select, .do-not-select *)").css("color", "red");

JS Fiddle demo

这会将第二个参数传递给否定选择器(.do-not-select *),并将:not()选择器与<form>元素分开(因为您选择的所有表单除了那些类.do-not-select),而不是过滤掉后代元素。