双击table事件, 以及获取当前行的数据

<html xmlns="http://www.w3.org/1999/xhtml" >  
<head runat="server">  
    <title>无标题页</title>  
    <script type="text/javascript">

  // 双击订单类型为"自修订单"或"维修订单"时弹出问题详情页事件
  function getQuestionDetail() {
    var rows = document.getElementById("data-grid").rows; // 获取表格所有行
    if(rows.length>0){ // 行数大于0
      for(var i=1; i<rows.length; i++){ // 遍历行数
          (function(i){ // 每一行的触发事件
          var obj = rows[i]; // 每一行的行对象
          var cols = obj.cells; // 获取所有列对象
          obj.ondblclick = function(){ // 双击触发
            alert(cols[2].innerHTML); // 获取当前行的第几列数据, 这里获取地址


          };
        })(i)
      }
    }
  }

    window.onload=function(){Test();}  
    </script>  
</head>  
<body>  
    <form id="form1" runat="server">  
      
    <table id="data-grid" border="1">  
        <tr>  
            <th>序号</th>  
            <th>名称</th>  
            <th>地址</th>  
        </tr>  
        <tr>  
            <td>1<input id="hd1" type="hidden" value="hd1" /></td>  
            <td>南大</td>  
            <td>长沙市  
            </td>  
        </tr>  
        <tr>  
            <td>2<input id="hd2" type="hidden" value="hd2" /></td>  
            <td>南大2</td>  
            <td>长沙市2  
            </td>  
        </tr>  
    </table>  
      
    </form>  
</body>  
</html>  

  

posted @ 2017-05-22 14:48  半生戎马,共话桑麻、  阅读(1757)  评论(0)    收藏  举报
levels of contents