如何获得输入焦点或不使用jQuery [英] How to get input has focus or not using jquery

查看:97
本文介绍了如何获得输入焦点或不使用jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取HTML的输入标签有焦点或不使用jquery



如果输入,图像等标签具有焦点,keydown事件将适用于表单。但它不会工作,它的焦点是形式,但不是像输入,图像等任何标签。
我该如何解决这个问题。
请帮助
提前致谢

$('#title')。focusout(function()
{
/ 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屋!

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