jquery 현재 요소 표가 있는 행렬 수 가져오기

2451 단어 jquery
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head> 
<title>tableTest.html</title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.min.js"></script>
<script type="text/javascript"> 
//          
$(document).ready(function() { 
//    td       click   
//    table id table1,   table1   td click     : 
// var tds = $("#table1").find("td"); 
var tds = $("td"); 
tds.click(tdclick); 
}); 

function tdclick() { 
//var td = $(this); 
//var text = td.text(); 
// $(this)    td   , 
// .parent("tr")    td     
// .prevAll()    tr      tr 
var hang = $(this).parent("tr").prevAll().length; 
var lie = $(this).prevAll().length; 
hang = Number(hang)+1;//        
lie = Number(lie)+1; 
alert(" "+hang+" "+" "+lie+" "); 
} 
</script> 
</head> 

<body> 
<table border="1px" width="300" id="table1"> 
<tr> 
<td> 
1 
</td> 
<td> 
2 
</td> 
<td> 
q 
</td> 
<td> 
t 
</td> 
</tr> 
<tr> 
<td> 
a 
</td> 
<td> 
2 
</td> 
<td> 
q 
</td> 
<td> 
y 
</td> 
</tr> 
<tr> 
<td> 
b 
</td> 
<td> 
2 
</td> 
<td> 
3 
</td> 
<td> 
b 
</td> 
</tr> 
<tr> 
<td> 
c 
</td> 
<td> 
2 
</td> 
<td> 
q 
</td> 
<td> 
4 
</td> 
</tr> 
<tr> 
<td> 
d 
</td> 
<td> 
2 
</td> 
<td> 
q 
</td> 
<td> 
f 
</td> 
</tr> 
</table> 
</body> 
</html>

좋은 웹페이지 즐겨찾기