Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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
Jquery中的焦点函数_Jquery_Function_Focus - Fatal编程技术网

Jquery中的焦点函数

Jquery中的焦点函数,jquery,function,focus,Jquery,Function,Focus,此函数用于在单击文本框时将其背景色更改为红色。我想知道当它没有被点击的时候,我如何使它恢复到原来的颜色 $('#textfield').focus(function() { $(this).css('background-color','red'); }); 您可以使用blur、addClass()和removeClass()来实现以下目的: $('#textfield')。焦点(函数(){ $(this.addClass('red'); }); $('#textfield').

此函数用于在单击文本框时将其背景色更改为红色。我想知道当它没有被点击的时候,我如何使它恢复到原来的颜色

$('#textfield').focus(function() {
    $(this).css('background-color','red');
}); 

您可以使用
blur
addClass()
removeClass()
来实现以下目的:

$('#textfield')。焦点(函数(){
$(this.addClass('red');
}); 
$('#textfield').blur(函数(){
$(this.removeClass('red');
}); 
.red{
背景色:红色;
}

@user3557489很高兴这有帮助,别忘了标记已解决的问题:)