Javascript 如何在Chrome/Firefox中结合自动聚焦选择页面加载时输入的所有文本

Javascript 如何在Chrome/Firefox中结合自动聚焦选择页面加载时输入的所有文本,javascript,html,google-chrome,firefox,opera,Javascript,Html,Google Chrome,Firefox,Opera,我的问题是:我如何说服Chrome/Opera和Firefox在加载页面时/之后(通过使用自动聚焦),以及在默认情况下选择其文本时,对特定输入进行聚焦 与我的用例最接近的答案是,当元素通过单击获得焦点时,如何选择输入的文本 对于我的问题,最恰当的答案是: //文件:scripts.js 函数onFocusSelectAll(发送方){ //edge和safari需要setTimeout(函数(){…},0) setTimeout(函数(){ sender.select(); }, 0); }

我的问题是:我如何说服Chrome/Opera和Firefox在加载页面时/之后(通过使用自动聚焦),以及在默认情况下选择其文本时,对特定输入进行聚焦

与我的用例最接近的答案是,当元素通过单击获得焦点时,如何选择输入的文本

对于我的问题,最恰当的答案是:

//文件:scripts.js
函数onFocusSelectAll(发送方){
//edge和safari需要setTimeout(函数(){…},0)
setTimeout(函数(){
sender.select();
}, 0);
}

玩了一会后,我发现我的解决方案实际上是正确的

//文件:scripts.js
函数onFocusSelectAll(发送方){
//edge和safari需要setTimeout(函数(){…},0)
setTimeout(函数(){
sender.select();
}, 0);
}