Javascript有没有办法得到当前获得焦点的对象引用?

zhwb36 2004-09-21 06:42:05
Javascript有没有办法得到当前获得焦点的对象引用?
...全文
219 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
soonquick 2004-09-22
  • 打赏
  • 举报
回复
document.activeElement
JasonJHu 2004-09-22
  • 打赏
  • 举报
回复
srcElement Property

--------------------------------------------------------------------------------

Retrieves the object that fired the event.

Syntax

HTML N/A
Scripting [ oObject = ] event.srcElement

Possible Values

oObject Object that specifies the event that fired.

The property is read-only with no default value.

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.

Sample Code

<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>

Applies To

[ Object Name ]
Platform Version
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
HTML N/A
Scripting event

Move the mouse cursor over an element in the Applies To List to display availability information for the listed platforms.
micker 2004-09-21
  • 打赏
  • 举报
回复
event.srcElement
yjgx007 2004-09-21
  • 打赏
  • 举报
回复
document.activeElement
chinchy 2004-09-21
  • 打赏
  • 举报
回复
event.srcElement

87,921

社区成员

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

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