在此示例中,我们使用
not()函数的
条件属性。在这里,
not()函数返回与类名
para 不匹配的所有段落元素。有一些div元素,段落元素等。在与类
para 相关的四个段落中,有两个段落元素。
我们必须单击给定的按钮才能看到结果。
<!DOCTYPE html> <html> <head> <style> div{ font-size: 20px; font-weight: bold; } </style> <script src="/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> function fun(){ $(document).ready(function(){ $("p").not(".para").css({"background": "yellow"}); }); } </script> </head> <body> <h2> Welcome to the lidihuo.com </h2> <h4> This is an example of using the jQuery's not() method. </h4> <div id = "div1"> This is first div element. </div> <p class = "para"> P1 with class = "para" </p> <div id = "div2"> This is second div element. </div> <p> P2. </p> <p> P3. </p> <p class = "para"> P4 with class = "para". Click the following button to see the effect. </p> <button onclick = "fun()"> click me </button> </body> </html>
输出
Welcome to the lidihuo.com
This is an example of using the jQuery's not() method.
This is first div element.
P1 with class = "para"
This is second div element.
P2.
P3.
P4 with class = "para". Click the following button to see the effect.
<!DOCTYPE html> <html> <head> <style> div{ font-size: 20px; font-weight: bold; } </style> <script src="/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> function fun(){ $(document).ready(function(){ $("p").not(function(index) { if(index == 1 || index == 2){ return true; } }).css({"background": "yellow"}); }); } </script> </head> <body> <h2> Welcome to the lidihuo.com </h2> <h4> This is an example of using the jQuery's not() method. </h4> <div id = "div1"> This is first div element. </div> <p class = "para"> P1 with class = "para" </p> <div id = "div2"> This is second div element. </div> <p> P2. </p> <p> P3. </p> <p class = "para"> P4 with class = "para". Click the following button to see the effect. </p> <button onclick = "fun()"> click me </button> </body> </html>
输出
Welcome to the lidihuo.com
This is an example of using the jQuery's not() method.
This is first div element.
P1 with class = "para"
This is second div element.
P2.
P3.
P4 with class = "para". Click the following button to see the effect.