Let*_*yer 7 javascript jquery textbox focus
如何找到当前文本框(或textarea)的焦点?我不在乎知道它是哪一个,我只需要知道,如果一个处于焦点(有光标在里面).我如何用javascript和jquery做到这一点?
Tha*_*hai 19
自从找到后document.activeElement,您可以检查其nodeName.
if (document.activeElement.nodeName == 'TEXTAREA' || document.activeElement.nodeName == 'INPUT') {
// ....
}
Run Code Online (Sandbox Code Playgroud)
这样的事情.
好吧,只是搞清楚了.这是我做的:
function checkFocus() {
if ($(document.activeElement).attr("type") == "text" || $(document.activeElement).attr("type") == "textarea") {
//Something's selected
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18250 次 |
| 最近记录: |