简体   繁体   English

JS:除非单击,否则阻止文本输入字段获得焦点

[英]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.

相关问题 如何防止输入字段获得键盘焦点? - How to prevent input fields from gaining keyboard focus? 如何阻止iframe在博客中获得关注? - How to prevent iframe from gaining focus in blogger? 如果未单击其他输入字段,请继续关注文本输入字段 - keep focus on text input field if another input field is not clicked 单击输入时防止父元素消失焦点 - prevent parent element from to disappear focus when input is clicked 除非单击 ReactJs,否则无法识别输入字段值 - Input field value not recognized unless clicked on ReactJs 将文字输入聚焦在TouchableHighlight上 - Focus text input on TouchableHighlight clicked 除非窗口焦点对准,否则文本字段不会焦点 - Text field won't focus unless window is in focus 防止iPhone Web应用程序滚动输入字段的焦点 - Prevent iPhone web-app from scrolling on focus of an input field 使用Angular JS中的复选框启用并设置焦点到文本输入字段 - Enable and set focus to text input field with checkbox in Angular JS 将输入字段追加到其他容器后,除非再次单击,否则无法继续输入文本输入。 它失去焦点 - After appending input field to a different container, I cannot continue typing in the text input unless I click again. It loses focus
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM