' x'之间的区别和' clientX' javascript中事件的属性

时间:2018-06-05 17:05:47

标签: javascript

' x'有什么区别?和' clientX'事件的属性' javascript中的对象?

在下面的代码中。我试图在' x'之间进行区分。和' clientX'事件对象的属性,但我正在获得' x'和' clientX'在控制台中。



<html>
<head><title>event property </title>
<script language="javascript">
function detect(e){
   console.log("event is fired on "+e.currentTarget.id+" X="+e.x+" Y="+e.y+" offsetX="+e.offsetX+" offsetY="+e.offsetY+" clientX="+e.clientX+" clienty="+e.clientY+" screenX="+e.screenX+" screenY="+e.screenY);
   
}



</script>
 </head>
<body onclick="detect(event);" id="body">
<div onclick="detect(event);" id="parent-div" style="position:fixed; top:10px; left:10px; width:400; height:400px; border:2px; border-style:solid;  border-color:red; "> 
<div onclick="detect(event);"  id="div" style ="width:300px; height:300px; position:fixed; top:100px; left:100px;  border:2px; border-style:solid; border-color: black;  ">


<img id="image" src="photo1.jpg" onclick="detect(event);" style="width:200px; height:200px; position:relative; top:50px; left: 50px; border:2px; border-style:solid; border-color:purple;"/>
</div> 
</div>
</body>
</html>

 
 
 
 
 
 
 
 
 
 
 
 
&#13;
&#13;
&#13;

&#39; x&#39;与&#39; clientX&#39;?

相同

1 个答案:

答案 0 :(得分:1)

MouseEvent.x属性是MouseEvent.clientX属性的别名。请参阅MDN文档:https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/x