jQuery ?? - ???
??? ?? ??
?? ???? ? ?? ??? ??? first(), last() ? eq()??, ?? ???? ?? ?? ?? ??? ?? ?? ??? ??? ? ????.
filter() ? not()? ?? ?? ??? ??? ???? ??? ??? ????? ???? ?? ??? ??? ? ????.
first() ???
first() ???? ??? ??? ? ?? ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("div p").first().css("background-color","blue"); }); </script> </head> <body> <div> <p>段落1</p> </div> <div> <p>段落2</p> </div> <p>段落3</p> </body> </html>
? ?? <div> ?? ??? ? ?? <p> ??? ?????.
last() ???
last() ???? ??? ?? ? ??? ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("div p").last().css("background-color","red"); }); </script> </head> <body> <div> <p>段落1</p> </div> <div> <p>段落2</p> </div> <p>段落3</p> </body> </html>
??? <div> ?? ??? ??? <p> ??? ?????.
eq() ???
eq() ???? ??? ?? ? ??? ??? ??? ?? ??? ?????.
??? ??? 0?? ????? ? ?? ??? ??? ??? 1? ?? 0???.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").eq(1).css("background-color","green"); }); </script> </head> <body> <p>php中文網(wǎng) (index 0).</p> <p>http://ipnx.cn (index 1)。</p> <p>google (index 2).</p> <p>http://www.google.com (index 3)。</p> </body> </html>
? ?? <p> ??(?? 1)? ?????.
filter() ???
filter() ???? ???? ??? ??? ? ????. ? ??? ???? ?? ??? ????? ???? ???? ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p").filter(".url").css("background-color","yellow"); }); </script> </head> <body> <p>php中文網(wǎng) (index 0).</p> <p class="url">http://ipnx.cn (index 1)。</p> <p>google (index 2).</p> <p class="url">http://www.google.com (index 3)。</p> </body> </html>
??? ??? "url"? ?? <p> ??? ?????.
not() ???
not() ???? ??? ???? ?? ?? ??? ???????.
?: not() ???? filter()? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("p").not(".url").css("background-color","gray"); }); </script> </head> <body> <p>php中文網(wǎng) (index 0).</p> <p class="url">http://ipnx.cn (index 1)。</p> <p>google (index 2).</p> <p class="url">http://www.google.com (index 3)。</p> </body> </html>
??? ?? "url"? ?? ?? <p> ??? ?????.