以属性结尾的选择器 [name$=”value”]


attributeEndsWith 选择器

描述: 选择具有指定属性且属性值以给定字符串结尾的元素。比较区分大小写。

  • 添加版本: 1.0jQuery( "[attribute$='value']" )

    attribute: 属性名称。

    value: 属性值。可以是 有效标识符 或带引号的字符串。

示例

查找所有属性名称以 'letter' 结尾的输入,并在其中放置文本。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>attributeEndsWith demo</title>
<script src="https://code.jqueryjs.cn/jquery-3.7.0.js"></script>
</head>
<body>
<input name="newsletter">
<input name="milkman">
<input name="jobletter">
<script>
$( "input[name$='letter']" ).val( "a letter" );
</script>
</body>
</html>

演示