<body >
<table height="200" width="200" style="position:absolute;top:200;left:20;background:red" border="1">
<tr id="row1" οnmοuseοver="show_id()"><td id="td1">aa</td></tr>
<tr id="row2" οnmοuseοver="show_id()"><td id="td2">bb</td></tr>
<tr id="row3" οnmοuseοver="show_id()"><td id="td3">cc</td></tr>
<tr id="row4" οnmοuseοver="show_id()"><td id="td4">dd</td></tr>
<tr id="row5" οnmοuseοver="show_id()"><td id="td5">ee</td></tr>
</table>
<a id="aa" href="javascript:void(0);" οnclick="alert(event.srcElement.id);">test SrcElement</a><br>
<input type="text" id="txt"/>
<script type="text/javascript">
function show_id() {
obj = event.srcElement;
alert(obj.id);
if (obj.tagName == 'TD')
document.getElementById('txt').value = obj.parentElement.id
}
</script>
</body>
1. event.srcElement 获取当前事件触发对象
2.obj.tagName=='TD'对象的标签名等于TD
3.obj.parentElement.id 对象的父标签的id属性
[img]http://cindysaj.iteye.com/upload/attachment/56223/d998e3ef-2178-34cc-9f9d-b9c16a4f58b2.jpg[/img]
[img]http://cindysaj.iteye.com/upload/attachment/56232/bc6f32a4-856a-353a-8f21-3879cdb20f77.jpg[/img]
<table height="200" width="200" style="position:absolute;top:200;left:20;background:red" border="1">
<tr id="row1" οnmοuseοver="show_id()"><td id="td1">aa</td></tr>
<tr id="row2" οnmοuseοver="show_id()"><td id="td2">bb</td></tr>
<tr id="row3" οnmοuseοver="show_id()"><td id="td3">cc</td></tr>
<tr id="row4" οnmοuseοver="show_id()"><td id="td4">dd</td></tr>
<tr id="row5" οnmοuseοver="show_id()"><td id="td5">ee</td></tr>
</table>
<a id="aa" href="javascript:void(0);" οnclick="alert(event.srcElement.id);">test SrcElement</a><br>
<input type="text" id="txt"/>
<script type="text/javascript">
function show_id() {
obj = event.srcElement;
alert(obj.id);
if (obj.tagName == 'TD')
document.getElementById('txt').value = obj.parentElement.id
}
</script>
</body>
1. event.srcElement 获取当前事件触发对象
2.obj.tagName=='TD'对象的标签名等于TD
3.obj.parentElement.id 对象的父标签的id属性
[img]http://cindysaj.iteye.com/upload/attachment/56223/d998e3ef-2178-34cc-9f9d-b9c16a4f58b2.jpg[/img]
[img]http://cindysaj.iteye.com/upload/attachment/56232/bc6f32a4-856a-353a-8f21-3879cdb20f77.jpg[/img]