<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>我有作业要做。我必须创建一个矩形,然后拖拽它。但是我可以在火狐中捕捉到e.which。它在chrome和ie9中工作正常。但在firefox中不起作用
发布于 2012-03-31 14:48:58
使用...而不是传递参数。
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
发布于 2012-03-31 14:57:55
看看这个
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>https://stackoverflow.com/questions/9953651
复制相似问题