[code="js"]<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<table id="test44" cellspacing="1" border="1" class="tablesorter">
<thead>
<tr>
<th>
First Name
</th>
<th>
Second Name
</th>
<th>
Age
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
[/code]
这是testPage 我想给table的每一个行加上点击事件,点击一行,就要弹出这行是第几行,但是一直是得到的最后一行数据,要用闭包来保存数据,大虾们,怎么写恩
[b]问题补充:[/b]
谢谢大虾们。问题解决了恩
[code="js"]tr.attachEvent("onclick",function(i){ return function(){alert(i)}}(i));
// tr.onclick=function(i){return function(){alert(i)}}(i)[/code]
[code="java"]<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<table id="test44" cellspacing="1" border="1" class="tablesorter">
<thead>
<tr id="test">
<th>
First Name
</th>
<th>
Second Name
</th>
<th>
Age
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
[/code]
上面多了个加粗的代码,改了下!
[code="java"]
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<table id="test44" cellspacing="1" border="1" class="tablesorter">
<thead>
<tr>
<th>
First Name
</th>
<th>
Second Name
</th>
<th>
Age
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
[/code]
你现在还在用原始js写哦,代码好多哦,用jquery吧,很简单的!如果用jquery的话用下面的方法就可以了!
[code="java"]
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<table id="test44" cellspacing="1" border="1" class="tablesorter">
<thead>
<tr id="test">
<th>
First Name
</th>
<th>
Second Name
</th>
<th>
Age
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
[/code]
代码就2行