强调一个元素的例外。 (jQuery的) [英] Force focus on one element with an exception. (jQuery)

查看:126
本文介绍了强调一个元素的例外。 (jQuery的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个输入字段。除非在#input上,否则无论用户点击哪个位置,我都会强制关注#area。我试过类似的东西,但是因为输入是文档的一部分,所以不起作用。

$ $ $ $ $ $ $#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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆