如何使 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>

更新於:2019 年 12 月 6 日

1K+ 觀看

開啟你的 職業生涯

完成該課程並獲得認證

開始學習
廣告