[英]JS: prevent text input field from gaining focus unless clicked
When I use Chrome on Android to fill a web form, by pressing the blue "enter" button the browser auto focuses on the next text field. 当我在Android上使用Chrome浏览器填写网络表单时,通过按蓝色的“输入”按钮,浏览器将自动聚焦于下一个文本字段。 How can I prevent this from happening?
如何防止这种情况发生?
<form action="/action_page.php" method="get"> <input name="text1" value="Bla bla"><br> <input name="text2" value="Some text"><br> <input type="submit" value="Submit"> </form>
If anyone is curious why I need this, see here (the answer to that question does not solve my actual problem even though it solved the toy version of it). 如果有人好奇为什么我需要这样做, 请参阅此处 (该问题的答案即使解决了它的玩具版本也不能解决我的实际问题)。
To disable autofocus on all input elements use this. 要在所有输入元素上禁用自动对焦,请使用此功能。
$(function(){
$('input').blur();
});
To disable autofocus on a particular element, pass the element id as below: 要禁用对特定元素的自动对焦,请按如下所示传递元素ID:
$(function(){
$('input#someid').blur();
});
OR you can use this 或者你可以使用这个
$('input').each(function() {
$(this).attr('tabindex', '-1');
});
Simply 只是
<form action="/action_page.php" method="get">
<input name="text1" value="Bla bla" tabindex="-1"><br>
<input name="text2" value="Some text" tabindex="-1"><br>
<input type="submit" value="Submit">
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.