length属性获取jQuery元素集合中元素的个数。

语法结构:

$(selector).length

代码实例:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>蚂蚁部落</title>
<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#btn").click(function () {
    $("div").text($("li").length);
  })
})
</script>
</head>
<body>
<div></div>
<ul>
  <li>后台专区</li>
  <li>前台专区</li>
  <li>数据库专区</li>
  <li>站长专区</li>
</ul>
<input type="button" value="查看效果" />
</body>
</html>

http://www.softwhy.com/article-997-1.html

http://www.softwhy.com/qiduan/jQuery_source/

http://www.softwhy.com/

相关文章:

  • 2022-12-23
  • 2022-02-05
  • 2021-05-24
  • 2021-06-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-21
  • 2021-12-19
  • 2022-12-23
  • 2022-01-08
  • 2021-12-25
  • 2021-07-22
相关资源
相似解决方案