我想找出鼠标点击事件在页面上的坐标。我写了一小段JS,它在Chrome上运行得很好,但在firefox上就不行了。似乎默认的全局'event‘在Firefox中不可用。以下是在Chrome上运行的代码的一个较小版本:
$("body").click(function() {
if (event == undefined) // for Chrome, 'event' is not undefined here
var event = window.event;
var xx;
var yy
html
<div id="cube" onmousemove= coordinate(event)></div>
<p id= "text"></p>
css
#cube{
width: 300px;
height: 300px;
border: 2px solid black;
}
和js
function cordinate(a){
var x = a.clientX;
var y = a.clientY;
var cor = "cordinate