如何关注div? [英] How to focus div?
本文介绍了如何关注div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请不要向我扔石头,因为我是js和jquery的新手。
是否可以集中一个div?
我只是想要在点击div时处理事件,或者专注于当我们点击div之外时。类似的东西:
Please don't throw stones at me because i'm total newbie at js and jquery. is it possible to focus a div? i just wanted to process events when div is clicked OR is focused and when we click outside the div. Something like that:
HTML:
<div id="focusedDiv"></div>
JS:
$("#focusedDiv").focus(function () {
....
});
$("#focusedDiv").focusout(function () {
....
});
提前致谢!
Thanks in advance!
推荐答案
您必须设置tabindex属性:
You have to set tabindex attribute:
<div id="focusedDiv" tabindex="-1"></div>
或者:
Or:
$("#focusedDiv").attr('tabindex',-1).focus(function () {
....
});
对于样式,您可以设置大纲的CSS属性:
For style, you could set outline CSS property too:
$("#focusedDiv").css('outline',0).attr('tabindex',-1).focus(function () {
....
});
这篇关于如何关注div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文