如何获得输入焦点或不使用jQuery [英] How to get input has focus or not using jquery
问题描述
如何获取HTML的输入标签有焦点或不使用jquery
如果输入,图像等标签具有焦点,keydown事件将适用于表单。但它不会工作,它的焦点是形式,但不是像输入,图像等任何标签。
我该如何解决这个问题。
请帮助
提前致谢
$('#title')。focusout(function()$如果($(document.activeElement).is(:focus))
{
/ code>
{
alert('focus');
}
其他
{
alert('not focus');
}
});
//这将不起作用
你可以这样做:
$ p $ if($(#id)。is(:focus)){
alert('focus');
}
How to get input tag of html has focus or not using jquery
keydown event will work for form if input,image etc. tag has focus. but it will not work it focus is on form but not on any tags like input,image etc. How can I solve this. Please help Thanks in advance
$('#title').focusout(function()
{
if($(document.activeElement).is(":focus"))
{
alert('focus');
}
else
{
alert('not focus');
}
});
// this will not work
you can do it by
if ($("#id").is(":focus")) {
alert('focus');
}
这篇关于如何获得输入焦点或不使用jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!