如何在onclick事件中捕获当前的event对象?(对各种浏览器,的相同实现)

signboy 2004-09-27 05:52:52
如何在onclick事件中捕获当前的event对象?(对各种浏览器,的相同实现)

document.onmousedown = elementClick;

function elementClick(e) {
//Purpose: Handle all clic
...
}

可以自动把event对象传递给elementClick函数,

对于button对象来说,
<input type="button" onclik ="callFunc('2')">
如何能把event传递给callFunc函数呢?
...全文
336 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fason 2004-09-27
  • 打赏
  • 举报
回复
function elementClick(e) {
//Purpose: Handle all clic
e = window.event || e;
var src = e.srcElement || e.target;
//src is what you want
}
梅雪香 2004-09-27
  • 打赏
  • 举报
回复
Syntax

event.srcElement [ = oObject ]
Possible Values

oObject Object that specifies or receives the event that fired.

The property is read/write. The property has no default value.

Expressions can be used in place of the preceding value(s), as of Microsoft® Internet Explorer 5. For more information, see About Dynamic Properties.

Remarks

The property is read-only in Microsoft® Internet Explorer 4.0, and read/write in Internet Explorer 5 and later.

Example

This example uses the srcElement property to retrieve the parent object, if needed, create the text range, move to the original object, and select the first word in the object.

HideExample

<SCRIPT LANGUAGE="JScript">
function selectWord() {
var oSource = window.event.srcElement ;
if (!oSource.isTextEdit)
oSource = window.event.srcElement.parentTextEdit;
if (oSource != null) {
var oTextRange = oSource.createTextRange();
oTextRange.moveToElementText(window.event.srcElement);
oTextRange.collapse();
oTextRange.expand("word");
oTextRange.select();
}
}
</SCRIPT>
Standards Information

There is no public standard that applies to this property.

87,901

社区成员

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

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