javascript - 跨浏览器输入文本焦点系统?

标签 javascript html focus

我有以下代码,其中soundid是0到11之间(不包括)的整数,并且所有元素名称都存在。目前,它并不关注许多浏览器。我应该添加、修改或更改它以使其能够聚焦到 input type="text" 元素?

代码:

document.getElementById("fo" + soundid + "cus").click();
document.getElementById("fo1cus").click();
$("#spellingf" + soundid).select();
$("#spellingf" + soundid).focus();
document.getElementById("spellingf" + soundid).focus();
$("#fo" + soundid + "cus").click();

谢谢!

最佳答案

原生 HTML 元素没有 click 方法。所以这个:

document.getElementById("fo" + soundid + "cus").click();

还有这个:

document.getElementById("fo1cus").click();

会抛出错误。该错误将停止代码执行,其余代码将不会执行。这就是为什么它不起作用。所以使用这段代码:

$("#fo" + soundid + "cus").click();
$("#fo1cus").click();
$("#spellingf" + soundid).focus();
$("#fo" + soundid + "cus").click();

关于javascript - 跨浏览器输入文本焦点系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10394773/

相关文章:

javascript - 是否可以修改 Location 对象的现有属性,例如 "location.href"?

javascript - 文本区域上的 TinyMCE : text between tags is not shown

javascript - 将 HTML 代码保存为自己的应用程序

javascript - 如何以编程方式将表格滚动到特定的 tr

windows - 如何让 VB.net 2008 应用程序窃取 Windows 7 上的焦点?

javascript - SVG foreignObject 不在 Safari 中显示

javascript - document.ready() 函数未执行,在开发控制台中工作

javascript - 如何在打开模式的同一按钮单击上验证选择字段?

android - 在 ListView 中显示 EditText 时如何隐藏多个光标?

jQuery-:focus Triggering When Switching Windows/Tabs