强调一个元素的例外。 (jQuery的) [英] Force focus on one element with an exception. (jQuery)
本文介绍了强调一个元素的例外。 (jQuery的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ $ $ $ $ $ $#area )。焦点();
$(document).click(function(){$(#area)。focus()};
$(#input输入)。focus()};
想法?将其更改为
$(#area)解决方案
$(document).click(function(){$(#area)。focus()};
$(#input {e.stopPropagation(); $(#input)。focus()});
这将停止冒泡到文档的事件,只会被 #input
I have two input fields. I want to force the focus on #area no matter where the user clicks unless it is on #input. I've tried something like this, but since input is part of document, it does not work.
$("#area").focus();
$(document).click(function() { $("#area").focus() };
$("#input").click(function() { $("#input").focus() };
Thoughts?
解决方案
change it to
$("#area").focus();
$(document).click(function() { $("#area").focus() };
$("#input").click(function(e) { e.stopPropagation(); $("#input").focus() });
This will stop the event from bubbling up to the document, and will only be caught by the #input
这篇关于强调一个元素的例外。 (jQuery的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文