仅当光标焦点位于特定文本区域时才可以运行JavaScript函数吗?仅当光标焦点位于文本框内时才有Javascript
我想执行enter
键的按键操作,但是我不希望此事件列表程序只在页面上就位,而只在光标位于textarea
时有效(id是postcontent
)
举个例子,我使用的功能是这样的:
function onEnter(){
if(characterCode == 13)
{
console.log("Enter pressed");
}
}
只是作为一个开始,而我的工作出了问题的焦点...
我也有jQuery的我处置。
可能重复[如何检测按下使用jQuery键盘上输入?](http://stackoverflow.com/questions/979662/how-to-detect-press-enter-on-keyboard-using-jquery) – George 2014-10-17 09:56:24
http://stackoverflow.com/questions/6178431/how-to-catch-enter-keypress-on-textarea-but-not- shiftenter – George 2014-10-17 09:57:09
@George这个问题在哪里回答了只在特定文本焦点上运行的问题区域? – Francesca 2014-10-17 09:57:16