如何讓 jQuery 屬性選擇器對大小寫不敏感?
要讓 jQuery 屬性選擇器對大小寫不敏感,建立兩個按鈕並使用屬性選擇器操作輸入。
示例
你可以嘗試執行以下程式碼讓 jQuery 屬性選擇器對大小寫不敏感
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$( "input[name*='myclass' i]" ).css("background-color", "yellow");
});
$("#insensitive").click(function(){
$( "input[name*='myclass' i]" ).css("background-color", "blue");
});
// myclass input blue
$("#sensitive").click(function(){
$( "input[name*='myclass']" ).css("background-color", "blue");
});
});
</script>
</head>
<body>
<input name="myclass">
<input name="MYCLASS">
<br>
<button id="insensitive">Case insensitive</button>
<button id="sensitive">Case sensitive</button>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP