gpt4 book ai didi

Jquery 属性不包含选择器

转载 作者:行者123 更新时间:2023-12-01 08:41:39 25 4
gpt4 key购买 nike

是否有一个否定选择器? 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>

Uncaught Error: Syntax error, unrecognized expression:

这个非常接近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">

关于Jquery 属性不包含选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46442714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com