这个示例会输出 id=”nav” UL 下的 li 元素的数量(length)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <script src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js" type="text/javascript"></script> </head> <body> list 1: <ul id="nav"> <li>ssss</li> <li>aaaaa</li> <li>ddddd</li> <li>eeeee</li> </ul> list2: <ul id="nav2"> <li>sssss</li> <li>aaaaa</li> <li>ddddd</li> <li>eeeee</li> </ul> <a href="#" id="test" onClick="jq()">jQuery</a> <script> function jq(){ alert($("#nav li").length); } </script> </body> </html>
提示:你可以先修改部分代码再运行。
Related posts:
电子邮件地址不会被公开。 必填项已被标记为 *
名称 *
电子邮件 *
网站
评论
您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
Anti-spam word: (Required)* To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.