【发布时间】:2011-09-12 22:26:42
【问题描述】:
我正在升级脚本以使其跨浏览器。我目前的代码如下。
function testFocus(){
var testSelection = document.getElementById('chattext').contentWindow.
window.document.selection.createRange().parentElement();
while (testSelection)
{
if (testSelection.id == "chatContent") {
return true;
}
testSelection = testSelection.parentElement;
}
return false;
}
但是,以下代码不再适用于现代浏览器。目前,上面的代码必须选择文本。它只需要检查文本框是否有焦点。该函数用作按钮/javascript添加文本之前的检查。
【问题讨论】:
-
除了 Alex C 的帖子之外,您还可以在 MDN:developer.mozilla.org/en/DOM/document.activeElement 和 MSDN:msdn.microsoft.com/en-us/library/ms533065%28v=vs.85%29.aspx 中阅读有关
document.activeElement的信息
标签: javascript internet-explorer firefox cross-browser