JQUERY中INDEX使用要注意的地方

JQUERY中INDEX使用要注意的地方

定义:

  $("#id").index(obj)返回int类型

 

=========Demo===============

HTML:

<table id="tb">

  <tr id="tr">

    <td><span onclick="GetPos(this)">0</span></td>

    <td><span onclick="GetPos(this)">1</span></td>

    <td><span onclick="GetPos(this)">2</span></td>

    <td><span onclick="GetPos(this)">3</span></td>

  </tr>

JS:

  function GetPos(item){

    var clickItem=$(item);

    var pos = $("#tb tr") .eq(0).find("td").index(clickItem);//var pos = $("#tr td").index(clickItem);

    alert(pos);

  }

 

  错误写法:

        var pos = $("#tb tr") .eq(0).index(clickItem);

      or

      var pos = $("#tr").index(clickItem);

 

  注意:

    index的父元素是一个集合!!!

 

 

.....................................................................OVER

posted @ 2011-10-31 20:48  Bruce-He  阅读(302)  评论(0编辑  收藏  举报