屬性結尾選擇器 [name$=”value”]


attributeEndsWith 選擇器

說明: 選擇具有指定屬性,其值完全以給定字串結尾的元素。此比較具有大小寫敏感性。

  • 新增版本: 1.0jQuery( "[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.jquery.com/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>

示範