Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/411.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在焦点上添加类_Javascript_Jquery - Fatal编程技术网

Javascript 在焦点上添加类

Javascript 在焦点上添加类,javascript,jquery,Javascript,Jquery,我有一个textarea,我喜欢它,所以一旦有人点击textarea(或按f键(keycode 70)),其他一切都会消失,它会将类焦点添加到主体中 我怎样才能用jQuery做到这一点?再加上@Swadq所说的内容,来回答您的其余问题: $('textarea').focus(function() { $(this).addClass('focusClass'); }); //Listen for the 'f' key to be pressed $(window).keydown

我有一个textarea,我喜欢它,所以一旦有人点击textarea(或按f键(keycode 70)),其他一切都会消失,它会将类焦点添加到主体中


我怎样才能用jQuery做到这一点?

再加上@Swadq所说的内容,来回答您的其余问题:

$('textarea').focus(function() {
     $(this).addClass('focusClass');
});
//Listen for the 'f' key to be pressed
$(window).keydown(function(event) {
  if(event.keyCode === 70) {
    $('#textarea').focus();
  }
});
$('#textarea').focus(function() {
  $(body).addClass('focus');
});
关于衰落位,请参考以下内容: