当前位置:Gxlcms > JavaScript > 使用js判断控件是否获得焦点

使用js判断控件是否获得焦点

时间:2021-07-01 10:21:17 帮助过:3人阅读

使用JS获取具有焦点控件的ID:
代码如下:
$("#textID").click(function(){
var act = document.activeElement.id;
if(act == "textID" ){
 alert("true");
}else{
 alert("false");
}
} );

使用jquery获取具有焦点控件的ID:var act = $(document.activeElement).attr("id");
 ----------------------<input type="text" id="textID">

人气教程排行