clientX在firefox下为什么不能用

wisword 2007-12-29 11:48:41
代码很简单:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<script>
var x =10000;
function clt(e)
{
x += e?e.clientX:window.event.clientX;
alert(x);
}
window.onload = clt;
</script>
</body>
</html>
...全文
739 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
muxrwc 2007-12-29
  • 打赏
  • 举报
回复
HTMLEvents
不带clientX
要想获取
必须用MouseEvents


Table 17-3.

Event types Event type
Interface
B
C
Supported by/detail properties

abort
Event
yes
no
<img>, <object>

blur
Event
no
no
<a>, <area>, <button>, <input>, <label>, <select>, <textarea>

change
Event
yes
no
<input>, <select>, <textarea>

click
MouseEvent
yes
yes
screenX, screenY, clientX, clientY, altKey, ctrlKey, shiftKey, metaKey, button, detail

error
Event
yes
no
<body>, <frameset>, <img>, <object>

focus
Event
no
no
<a>, <area>, <button>, <input>, <label>, <select>, <textarea>

load
Event
no
no
<body>, <frameset>, <iframe>, <img>, <object>

mousedown
MouseEvent
yes
yes
screenX, screenY, clientX, clientY, altKey, ctrlKey, shiftKey, metaKey, button, detail

mousemove
MouseEvent
yes
no
screenX, screenY, clientX, clientY, altKey, ctrlKey, shiftKey, metaKey

mouseout
MouseEvent
yes
yes
screenX, screenY, clientX, clientY, altKey, ctrlKey, shiftKey, metaKey, relatedTarget

mouseover
MouseEvent
yes
yes
screenX, screenY, clientX, clientY, altKey, ctrlKey, shiftKey, metaKey, relatedTarget

mouseup
MouseEvent
yes
yes
screenX, screenY, clientX, clientY, altKey, ctrlKey, shiftKey, metaKey, button, detail

reset
Event
yes
no
<form>

resize
Event
yes
no
<body>, <frameset>, <iframe>

scroll
Event
yes
no
<body>

select
Event
yes
no
<input>, <textarea>

submit
Event
yes
yes
<form>

unload
Event
no
no
<body>, <frameset>

DOMActivate
UIEvent
yes
yes
detail

DOMFocusIn
UIEvent
yes
no
none

DOMFocusOut
UIEvent
yes
no
none
ychangh 2007-12-29
  • 打赏
  • 举报
回复
应该可以用的.我这里是可以用的.
要不改成pageX.
<script>
var x =10000;
function clt(e)
{
x += e?e.pageX:window.event.clientX;
alert(x);
}
window.onload = clt;
</script>
muxrwc 2007-12-29
  • 打赏
  • 举报
回复
:D
嗯..

window.onload触发的是HTMLElements

onclick触发的是MouseEvents
wisword 2007-12-29
  • 打赏
  • 举报
回复
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
<!--
#Layer1 {
position:absolute;
width:95px;
height:20px;
z-index:1;
}
-->
</style>
</head>
<body>
<div id="Layer1"><a id="clicklink" href="#">click here</a></div>
<script>
var x =10000;
function clt(e)
{
x += e?e.clientX:window.event.clientX;
alert(x);
}
document.getElementById('clicklink').onclick = clt;
</script>
</body>
</html>
这样就没问题了,楼上那张表我看过(http://blog.csdn.net/Xviewee/archive/2007/05/11/1604562.aspx),当时没看明白,现在懂了些了 。

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧