jquery 不要(或删除)关注任何表单字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6504758/
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
jquery don't (or remove) focus on any form field
提问by Markus
Possible Duplicate:
Jquery Unfocus
可能的重复:
Jquery Unfocus
Have a form with just one password field tag, and as I use palceholder, I don't want to have automatic input focus. How can I set no focus at all within jquery?
有一个只有一个密码字段标签的表单,当我使用 palceholder 时,我不想有自动输入焦点。如何在 jquery 中完全不设置焦点?
Thanks, Markus
谢谢,马库斯
回答by James Allardice
I'm not fully clear on what you need, but I think you're looking for something like this:
我不完全清楚你需要什么,但我认为你正在寻找这样的东西:
$("input").blur();
That will remove the focus from any input
element that may have it.
这将从input
可能拥有它的任何元素中删除焦点。
回答by Nathan MacInnes
You can disable the field. $('input.my-input').attr('disabled', true);
Then re-enable it when you want to allow input (on click or whatever). You'd have to use some CSS (.my-input:disabled { ... }
) to make sure the browser doesn't grey it out.
您可以禁用该字段。$('input.my-input').attr('disabled', true);
然后在您想要允许输入(单击或其他)时重新启用它。您必须使用一些 CSS ( .my-input:disabled { ... }
) 来确保浏览器不会使其变灰。