如何使 jQuery 属性选择器不区分大小写?

jqueryweb developmentfront end technology

要使 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>

相关文章