Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.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/84.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 jQuery:如何设置按钮背景色的样式?_Javascript_Jquery - Fatal编程技术网

Javascript jQuery:如何设置按钮背景色的样式?

Javascript jQuery:如何设置按钮背景色的样式?,javascript,jquery,Javascript,Jquery,我正在尝试使用jQuery开发一个网站。 我有以下代码: $(function () { $(".myButton").click(function() { alert("You clicked button!"); }); }); 如何更改类的背景色myButton?您可以使用this关键字更改其背景色,如下所示 $(函数(){ $(“.myButton”)。单击(函数(){ $(this.cs

我正在尝试使用
jQuery
开发一个网站。 我有以下代码:

$(function () {
       $(".myButton").click(function() {
           alert("You clicked button!");
       });
   });

如何更改类的背景色
myButton

您可以使用
this
关键字更改其背景色,如下所示

$(函数(){
$(“.myButton”)。单击(函数(){
$(this.css('background-color','red');
});
});

点击我
点击我
单击我
使用
$(此)

$(函数(){
$(“.myButton”)。单击(函数(){
$(this.css(“背景”、“红色”)
警报(“您点击了按钮!”);
});
});
按钮

如果您想使用jQuery执行此操作,那么它是:

$(“.myButton”)
.css(“背景色”、“绿色”)
.css(“颜色”、“白色”)
.css(“边界半径”,“5px”)
.css(“字体系列”、“机器人”)
.css(“边框”、“无”)
。单击(函数(){
$(this.css(“背景色”、“红色”);
});


点击我
嗯,我真不敢相信谷歌上没有答案