Jquery 在Javascript函数中将CSS背景色添加到按钮

Jquery 在Javascript函数中将CSS背景色添加到按钮,jquery,html,css,Jquery,Html,Css,我想给javascript函数中的按钮添加背景色。这是我的密码 $('theme')。在('click',函数(){ myApp.modal({ 垂直按钮:正确, 按钮:[ { 文本:“主题类别”, onClick:function(){ document.getElementById('content_01').style.display=“无”; document.getElementById('content_02').style.display=“block”; } }, { 文本:“

我想给javascript函数中的按钮添加背景色。这是我的密码

$('theme')。在('click',函数(){
myApp.modal({
垂直按钮:正确,
按钮:[
{
文本:“主题类别”,
onClick:function(){
document.getElementById('content_01').style.display=“无”;
document.getElementById('content_02').style.display=“block”;
}
},
{
文本:“所有主题”,
onClick:function(){
myApp.alert('您单击了第二个按钮!')
}
},
]
})
});

主题
尝试以下方法:

$(this).css('background-color','#f47121');

使用
this.style.backgroundColor=“red”

JQuery
$(this.css)(“背景色”,“红色”)

请看这里:

$('theme')。在('click',函数(){
this.style.backgroundColor=“red”;
myApp.modal({
垂直按钮:正确,
按钮:[
{
文本:“主题类别”,
onClick:function(){
document.getElementById('content_01').style.display=“无”;
document.getElementById('content_02').style.display=“block”;
}
},
{
文本:“所有主题”,
onClick:function(){
myApp.alert('您单击了第二个按钮!')
}
},
]
})
});

主题
您可以使用
$(this.css('background-color','red')

$('theme')。在('click',函数(){
$(this.css('background-color','red');
});


主题
给你一个解决方案

$('theme')。在('click',函数(){
myApp.modal({
垂直按钮:正确,
按钮:[{
文本:“主题类别”,
onClick:function(){
document.getElementById('content_01').style.display=“无”;
document.getElementById('content_02').style.display=“block”;
},
类名:“buttonRed”
},
{
文本:“所有主题”,
onClick:function(){
myApp.alert('您单击了第二个按钮!')
},
类名:“buttonRed”
}
]
})
});
.buttonRed{
背景:红色;
}


主题
$(“#主题”)。在('click',function(){
应该是
$(“#主题”)。在('click',function(){
必须是一个打字错误,我想,编辑问题试试
this.style.background='#FF00AA'
在onClick事件函数中您可以使用
id=“主题”
不止一次?你能不能显示你的myapp.jsI想给myapp.modal({}函数中的按钮添加背景色。不是为“主题”添加背景色Button@ChathuriFernando我已经更新了答案,请看一看。我想给myApp.modal({}函数中的按钮添加背景色。不用于“主题”button我想为myApp.modal({}函数中的按钮添加背景色。不用于“主题”按钮,请在
onClick
函数中使用它:
onClick:function(){this.style.backgroundColor=“red”;myApp.alert('您单击了第二个按钮!')