欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery實現(xiàn)獲取table中鼠標click點擊位置行號與列號的方法

 更新時間:2017年10月09日 11:43:09   作者:happymagic  
這篇文章主要介紹了jQuery實現(xiàn)獲取table中鼠標click點擊位置行號與列號的方法,涉及jQuery事件響應及針對table表格元素相關操作技巧,需要的朋友可以參考下

本文實例講述了jQuery實現(xiàn)獲取table中鼠標click點擊位置行號與列號的方法。分享給大家供大家參考,具體如下:

先來看看運行效果:

具體代碼如下:

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>www.dbjr.com.cn 鼠標點擊位置行列號</title>
</head>
<body>
<table class="mytable" border=1>
  <tr> 
   <th style="width: 160px;">表頭一</th> 
   <th style="width: 160px;">表頭二 </th> 
   <th style="width: 160px;">表頭三</th> 
   <th style="width: 160px;">表頭四</th> 
   <th style="width: 160px;">表頭五</th> 
  </tr> 
  <tr> 
   <td>第一行第一列</td> 
   <td>第一行第二列</td> 
   <td>第一行第三列</td> 
   <td>第一行第四列</td> 
   <td>第一行第五列</td> 
  </tr> 
  <tr> 
   <td>第二行第一列</td> 
   <td>第二行第二列</td> 
   <td>第二行第三列</td> 
   <td>第二行第四列</td> 
   <td>第二行第五列</td> 
  </tr> 
  <tr> 
   <td>第三行第一列</td> 
   <td>第三行第二列</td> 
   <td>第三行第三列</td> 
   <td>第三行第四列</td> 
   <td>第三行第五列</td> 
  </tr> 
  <tr> 
   <td>第四行第一列</td> 
   <td>第四行第二列</td> 
   <td>第四行第三列</td> 
   <td>第四行第四列</td> 
   <td>第四行第五列</td> 
  </tr> 
</table>
<script src="jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function(){
    $(".mytable td").click(function(){
      var tdSeq = $(this).parent().find("td").index($(this)[0]);
      var trSeq = $(this).parent().parent().find("tr").index($(this).parent()[0]);
      alert("第" + (trSeq + 1) + "行,第" + (tdSeq + 1) + "列");
    });
})
</script>
</body>
</html>

更多關于jQuery相關內(nèi)容感興趣的讀者可查看本站專題:《jQuery表格(table)操作技巧匯總》、《jQuery操作json數(shù)據(jù)技巧匯總》、《jQuery form操作技巧匯總》、《jQuery常用插件及用法總結》、《jQuery擴展技巧總結》及《jquery選擇器用法總結

希望本文所述對大家jQuery程序設計有所幫助。

相關文章

最新評論