Javascript 如何从提交按钮上移除焦点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2439565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove focus from submit button
提问by ant
回答by ant
This worked :
这有效:
var selectedInput = null;
$(document).ready(function() {
$('input, textarea, select').focus(function() {
this.blur();
});
});
回答by Brian Moeskau
Try this in your button's CSS, or that of the enclosing <a>if that's what you are using in the markup (reference):
在您的按钮的 CSS 中尝试这个,或者<a>如果这是您在标记中使用的(参考),则在封闭的 CSS 中尝试:
-moz-outline:0 none;
outline:0 none;
Bear in mind that it is a valuable accessibility/keyboard feature, so ideally you would provide some alternate focus hint that is more visually pleasing to you.
请记住,这是一项有价值的辅助功能/键盘功能,因此理想情况下,您可以提供一些在视觉上更令您满意的替代焦点提示。
回答by casraf
In your body or form...
在你的身体或形式...
<form onready="document.getElementById('submit').blur();">
...
<input type="submit" id="submit" />
</form>回答by naivists
The first submit button in a form is always "in focus", hence, when you hit enter, your form gets submitted.
表单中的第一个提交按钮始终处于“焦点”状态,因此,当您按 Enter 键时,您的表单将被提交。
See responses to a similar post: Stopping IE from highlighting the first submit-button in a form
查看对类似帖子的回复:Stopping IE from highlighting the first submit-button in a form
回答by cbmckay
You can code your button as:
您可以将按钮编码为:
<button onClick='this.form.submit()'>Button Text</button>
That removes the "submit" functionality to code and thus the focus problem.
这消除了代码的“提交”功能,从而消除了焦点问题。


