<html>
<script type="text/javascript">
function handleMouseEvent(context, element, type){
if (!evt)
var evt = ((window.event)?(event):(evt));
alert(evt);
}
</script>
<body>
<div id="contain">
<div id="parent_id" style="background-color:
lightblue;position: absolute;
left:50px; top:50px;
width: 200px; height: 75px;"
onmousedown="handleMouseEvent(this, 'parent_id', 1)"
onmouseup="save(this, 1)">
</div>
</div>
</body>
</html>
我有一份功课。我必须创建一个矩形然后拖放它。但是我可以在火狐中捕捉到它。
它在chrome和ie9中工作正常。但是在firefox中不起作用
答案 0 :(得分:0)
而不是传递参数,请使用...
function handleMouseEvent(e)
{
var evt = e || window.event;
//here you can get id by using evt.srcElement.id
}
或使用此...
function doSomething(e) {
var rightclick;
if (!e) var e = window.event;
if (e.which) rightclick = (e.which == 3);
else if (e.button) rightclick = (e.button == 2);
alert('Rightclick: ' + rightclick); // true or false
}
供您参考...... http://www.quirksmode.org/js/events_properties.html
答案 1 :(得分:0)
看这个,
https://developer.mozilla.org/en/DOM/window.onmousedown
Firefox本身将事件参数传递给函数。
我修改了MDN功能来帮助你。
<html>
<head>
<title>onmousedown test</title>
<script type="text/javascript">
window.onmousedown = mousedown;
function mousedown(e){
console.log(e.pageX);
console.log(e.pageY);
console.log(e.target)
}
</script>
</head>
<body>
<p>click and hold down the LH mouse button<br />
on the page to fire the mousedown event.</p>
</body>
</html>