jQuery 获取元素数量 length

3
172

jQuery 元素的数量 length

jQuery(selecter).length

这个方法会返回一共有多少个改元素。

在实际应用中,我们可以用它来判断目标HTML对象是否存在

if(jQuery(selecter).length > 0){
  // do next step
}

 

3 COMMENTS

  1. $(function(){
    $("#test").click(function(){
    alert($("#nav li").length();
    });
    })

  2. facebook find love –
    I’m amazed, I must say. Rarely do I come across a blog that’s both educative and
    amusing, and without a doubt, you have hit the nail on the head.
    The problem is an issue that not enough people are
    speaking intelligently about. I’m very happy I stumbled across this in my
    hunt for something regarding this.

LEAVE A REPLY

Please enter your comment!
Please enter your name here