我有以下代码来选择一个元素(将动态创建):
document.all['ele' + count].select()
上面的代码在 Google Chrome 中完美运行,但在所有版本的 Internet Explorer 中都会出错:
SCRIPT16389: Incorrect function.
有什么替代 .select()
的方法可以在 Google Chrome 和 IE 中工作?
编辑:
我将有以下Textarea
用于选择上述功能
<textarea name="ele[5][t]" id="ele5"></textarea>
最佳答案
select()
可能不是问题所在。几乎可以肯定是使用了 document.all
。
Javascript解决方案:
document.getElementById("ele" + count).select();
jQuery 解决方案:
$('#ele' + count)[0].select();
两者是等价的。
编辑
IE 似乎有一个关于隐藏输入的错误 (source) ,尝试使用 jQuery 来解决它:
$('#ele' + count).select();
或者:
$('#ele' + count).focus();
关于javascript - javascript 的 .select() 的替代品是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19652433/