【问题标题】:Put focus on XUL textbox将焦点放在 XUL 文本框上
【发布时间】:2011-11-25 13:39:47
【问题描述】:

我正在做一个 Firefox 扩展。该扩展程序有一个侧边栏。在这个侧边栏中,我动态创建了一些文本框。如何将焦点放在我创建的最后一个文本框上?

这是代码,我想把焦点放在文本框 "userResponse" 中。文本框是一个 XUL 元素。

var textResponse= document.createElement("textbox");
textResponse.setAttribute("id", "userResponse");
textResponse.setAttribute("class", "question");
textResponse.setAttribute("title", "Type your question here");
textResponse.onkeypress = numberOfResults;
textResponse.focus("");
var trResponse = document.createElement("tr");
var tdResponse = document.createElement("td");
tdResponse.appendChild(textResponse);
trResponse.appendChild(tdResponse);
tableQuestion.appendChild(trResponse);

我用document.getElementById("userResponse").focus() 试过了,但没有用。

【问题讨论】:

    标签: javascript firefox firefox-addon xul


    【解决方案1】:

    调用textResponse.focus() 是正确的方法 - 但没有参数并且将此元素添加到文档之后。当然,您可以使用document.getElementById() 再次检索该元素 - 但同样的事情,您应该将元素添加到文档后进行。

    【讨论】:

    • 是的弗拉基米尔,我在将元素添加到文档后进行了焦点操作,但没有任何反应。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多