简体   繁体   English

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

[英]Cross-browser input text focus system?

I have the following code, where soundid is an integer between (not including) 0 and 11, and all the element names exist. 我有以下代码,其中soundid是(不包括)0和11之间的整数,并且存在所有元素名称。 Currently, it does not focus in many browsers. 目前,它并不专注于许多浏览器。 What should I add, modify or change it into to make it able to focus into an input type="text" element? 我应该添加,修改或更改它以使其能够聚焦到input type="text"元素?

Code: 码:

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();

Thank you! 谢谢!

Native HTML Elements don't have an click method. 原生HTML元素没有click方法。 So this: 所以这:

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

and this: 和这个:

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

will throw an error. 会抛出错误。 The error will stop the code execution s the rest of the code won't be executed. 该错误将停止代码执行,其余代码将不会执行。 That's why it doesn't work. 这就是为什么它不起作用。 So use this code: 所以使用这段代码:

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

Not really sure what you're asking here tbh. 不确定你在这里问什么tbh。

Giving your input and id attribute and selecting on that id will work cross browser. 提供您的输入和id属性并选择该ID将跨浏览器工作。

$('#fo1cus').focus(function() {
  alert('Handler for .focus() called.');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM