JS判斷一個對象已獲得焦點document.activeElement.tagName //tagName 標(biāo)簽名
實例:判斷body獲得光標(biāo)時關(guān)閉輸入法。
復(fù)制代碼 代碼如下:
var act = document.activeElement.tagName.toLowerCase();
if(act.indexOf("body") != -1 || act.indexOf("html") != -1)
{
document.body.style.imeMode = 'disabled';
}
<script>
function test(){
var srcElem = document.activeElement
var testval = srcElem.name; //id和name比較常用應(yīng)該
alert("控件"+testval+"獲取焦點");
}
</script>
<input type="text" value="測試a">
<input type="text" value="測試b">
新聞熱點
疑難解答
圖片精選