对于这个问题,我现在基本明白了。event.x This property returns the x-coordinate of the closest relatively positioned parent element of the element that fires the event. If the event firing element is relatively positioned, then the x-coordinate from the boundary of the element is returned. If the event firing element and all of its parent elements are not relatively positioned, then the x property returns a coordinate relative to the body element.通过此贴,我知道了很多问题之外的东西,特别感谢Go_Rush(阿舜)、xuzuning(唠叨)!!!此贴加到50分,结贴!
tr就是td的父元素。
<br>
这个是Body,ID=BodyElement
<div id=DivElement style="border:1px blue solid;">
这个是DIV,ID=DivElement
<span id=GreenSpan style="width:200px;height:100px;border:1px green solid">
这个是SPAN,ID=GreenSpan
</span>
<span id=RedSpan style="width:300px;height:300px;border:1px red solid">
这个是SPAN,ID=RedSpan
</span>
</div>
<textarea id=TextAreaElement style="width:700px;height:100px;overflow:auto"></textarea>
<script language="Jscript">
function document::onmousemove(){
TextAreaElement.value="当前Element:\t"+event.srcElement.id+"\n当前Element的父Element:\t"+event.srcElement.parentElement.id+"\nevent.x:\t"+event.x
}
</script>
</body>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body onmousemove="window.status = 'X=' + window.event.x + ' Y=' + window.event.y">
<table width="500" border="1" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<br>
<table width="500" border="1" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<form name="form1" method="post" action="">
<input name="textfield" type="text" size="50">
<br>
<br>
<textarea name="textfield2" cols="50" rows="15"></textarea>
<br>
<br>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>地址栏显示的值都是相对于左上角的,那么a relatively positioned parent element是什么?
<HTML>
<HEAD>
<TITLE>键盘和鼠标事件测试</TITLE>
<script language="javascript">
function keyDown(e) {
s = event.srcElement.tagName+"<br>";
for(v in event)
s += v+"="+event[v]+"<br>";
view.innerHTML = s;
sss.innerHTML = event.screenX+","+event.screenY;
return false;
}
document.onkeydown=keyDown
document.onkeyup=keyDown
document.onmousedown=keyDown
document.onmouseup=keyDown
document.onmousemove=keyDown
document.onmouseover=keyDown
document.onmouseout=keyDown
document.onkeypress=keyDown
</script>
</HEAD> <BODY>
<p>请操作鼠标或键盘</p> <input type=text><span id="sss"></span>
<table border>
<tr><td>123</td><td>abc</td></tr>
</table>
<span id="view"></span>
</BODY>
</HTML>
This property returns the x-coordinate of the closest relatively positioned parent element of the element that fires the event. If the event firing element is relatively positioned, then the x-coordinate from the boundary of the element is returned. If the event firing element and all of its parent elements are not relatively positioned, then the x property returns a coordinate relative to the body element.通过此贴,我知道了很多问题之外的东西,特别感谢Go_Rush(阿舜)、xuzuning(唠叨)!!!此贴加到50分,结贴!