當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


JQuery 屬性包含[name*="value"]用法及代碼示例

用法
attributeContains selector

說明:選擇具有指定屬性且值包含給定子字符串的元素。

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

    attribute: 一個屬性名稱。

    value: 一個屬性值。可以是有效標識符或帶引號的字符串。

這是匹配值的最慷慨的 jQuery 屬性選擇器。如果選擇器的字符串出現在元素屬性值中的任何位置,它將選擇一個元素。將此選擇器與 Attribute Contains Word 選擇器(例如 [attr~="word"])進行比較,這在許多情況下更合適。

例子:

查找名稱屬性包含 'man' 的所有輸入,並使用一些文本設置值。

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>attributeContains demo</title>
  <script src="https://code.jquery.com/jquery-3.5.0.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>

演示:

相關用法


注:本文由純淨天空篩選整理自jquery.com大神的英文原創作品 屬性包含[name*="value"]。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。