為什么要用this 而不能直接用otr[i]
<!DOCTYPE html>
<html>
?<head>
? <title> new document </title> ?
? <meta http-equiv="Content-Type" content="text/html; charset=gbk"/> ??
? <script type="text/javascript">?
??
? ? ? window.onload = function(){
? ? ? ? ?var otab=document.getElementById('table');
var otr=otab.getElementsByTagName('tr');
? ? ? ? for(var i=0;i<otr.length;i++){
? ? ? ? ? ? otr[i].onmouseover=function(){
? ? ? ? ? ? ? ? this.style.backgroundColor='red';
? ? ? ? ? ? }
? ? ? ? }
?
}
? </script>?
?</head>?
?<body>?
? <table border="1" width="50%" id="table">
? <tr>
<th>學號</th>
<th>姓名</th>
<th>操作</th>
? </tr> ?
? <tr>
<td>xh001</td>
<td>王小明</td>
<td><a href="javascript:;" >刪除</a></td> ? <!--在刪除按鈕上添加點擊事件 ?-->
? </tr>
? <tr>
<td>xh002</td>
<td>劉小芳</td>
<td><a href="javascript:;" >刪除</a></td> ? <!--在刪除按鈕上添加點擊事件 ?-->
? </tr> ?
? </table>
? <input type="button" value="添加一行" ?/> ? <!--在添加按鈕上添加點擊事件 ?-->
?</body>
</html>
2016-06-23
我也是這個問題,求解答
2016-05-27
同類型問題,每2-3天就有一個人要問
http://idcbgp.cn/qadetail/136830