<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jquery selectors</title> <script src="https://cdn.staticfile.org/jquery/2.0.0/jquery.min.js"></script> </head> <body> <p class="a">a</p> <p class="a b">ab</p> <p class="a c">ac</p> <script> /*参考: https://www.runoob.com/jquery/jquery-selectors.html https://www.w3school.com.cn/jquery/jquery_ref_selectors.asp * */ $(function () { // 0. console.log($("p.a").html()); // a // 1.第一个 p 元素。 // $("p.a:first").html(); console.log($("p.a:eq(0)").html()); // a // 2.第二个 p 元素。 // $("p.a:last").html(); // $("p.a.b").html(); console.log($("p.a:eq(1)").html()); // ab // 3.p 的个数。 // console.log($("p")); let pLen = $("p").length; console.log("pLen:", pLen); // 3 console.log($("p.a:eq(" + (pLen - 1) + ")").html()); // ac }); </script> </body> </html>
jquery selectors.html
最新推荐文章于 2021-06-03 06:14:05 发布