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

参考资料:

-------------------------------------------------------------------------------------------------------------------------------------------------
数据库优化
数据库教程
数据库实战经验分享博客

百度云下载

评测


原文地址:https://www.cnblogs.com/longle/p/index.html