【问题标题】:Jquery attribute NOT contains selectorJquery 属性不包含选择器
【发布时间】:2017-09-27 16:17:00
【问题描述】:

是否有一个负选择器? 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 属性内。

【问题讨论】:

    标签: jquery


    【解决方案1】:

    使用:not()

    选择所有没有的输入(名称包含“人”)

    $( "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">

    【讨论】:

      猜你喜欢
      • 2012-04-17
      • 2014-02-14
      • 2013-12-02
      • 2012-03-06
      • 2011-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-06
      相关资源
      最近更新 更多