有否定选择器吗? https://api.jquery.com/attribute-contains-selector/

例如,查询所有输入,其中属性名称没有子字符串man

我尝试了明显的但没有用

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>attributeContains demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<input name="man-news">
<input name="milkman">
<input name="letterman2">
<input name="newmilk">

<script>
$( "input[name*!='man']" ).val( "has man in it!" );
</script>

</body>
</html>



未捕获的错误:语法错误,无法识别的表达式:


这个非常接近https://api.jquery.com/attribute-not-equal-selector/,但是不相等,我希望没有包含。

而这个jQuery "not contains" selector无效,因为我没有文本值,创建表单的方式是在value属性内。

最佳答案

使用:not()

选择所有不输入(名称包含“ man”的输入)



$( "input:not([name*='man'])" ).val( "DOESN'T have man in it!" );

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="man-news">
<input name="milkman">
<input name="letterman2">
<input name="newmilk">

10-05 20:53
查看更多