Javascript 如何更改按钮的颜色?

Javascript 如何更改按钮的颜色?,javascript,jquery,html,Javascript,Jquery,Html,如何更改“输入”和“更多信息”按钮的颜色这是我的脚本: $(document).on('pagebeforeshow', '#index', function(){ // Add a new select element $('<select>').attr({'name':'select-choice-1','id':'select-choice-1','data-native-menu':'false'}).appendTo('[data-role=

如何更改“输入”和“更多信息”按钮的颜色这是我的脚本:

$(document).on('pagebeforeshow', '#index', function(){    
    // Add a new select element 

     $('<select>').attr({'name':'select-choice-1','id':'select-choice-1','data-native-menu':'false'}).appendTo('[data-role="content"]');
     $('<select>').attr({'name':'select-choice-2','id':'select-choice-2','data-native-menu':'false'}).appendTo('[data-role="content"]');

    $('<option>').html('More info').appendTo('#select-choice-2');
    $('<option>').html('Enter').appendTo('#select-choice-1');
    $('<option>').attr({'value':'1'}).html('Instructions').appendTo('#select-choice-2');
    $('<option>').attr({'value':'2'}).html('Bookings').appendTo('#select-choice-2'); 
    $('<option>').attr({'value':'3'}).html('Newsletter').appendTo('#select-choice-2');     
    // Enhance new select element
    $('select').selectmenu();

    $(document).on('change', '#select-choice-2', function(){    
        alert($(this).find("option:selected").text());


    });    

});
$(document).on('pagebeforeshow','#index',function(){
//添加一个新的select元素
$(“”).attr({'name':'select-choice-1','id':'select-choice-1','data-native-menu':'false')).appendTo('data role=“content”]);
$(“”).attr({'name':'select-choice-2','id':'select-choice-2','data-native-menu':'false')).appendTo('[data role=“content”]');
$('').html('More info').appendTo('select-choice-2');
$('').html('Enter').appendTo('select-choice-1');
$('').attr({'value':'1'}).html('Instructions').appendTo('select-choice-2');
$('').attr({'value':'2'}).html('Bookings').appendTo('select-choice-2');
$('').attr({'value':'3'}).html('Newsletter').appendTo('select-choice-2');
//增强新选择元素
$('select')。selectmenu();
$(document).on('change','#select-choice-2',function(){
警报($(this).find(“选项:选定”).text();
});    
});

你真的需要帮助

这个页面的控制台中尝试一下,你将打开“发布你的答案”按钮的颜色

$("#submit-button").css('background-color','red');   


$(document).on('change', '#select-choice-2', function(){    
  alert($(this).find("option:selected").text());
  $("THIS-IS-WHERE-YOUR-HOOK-GOES").css('background-color','red');
});
你的钩子可以是很多东西,这里有几个例子

基于CSS类:“.按钮颜色” 基于ID:#我的按钮” 基于元素:“:button”

创建一个类并将其指定给类名,而不是指定给,如下所示:

$(“.button”).append(“您想要什么”)

然后在css中,您可以更改按钮的样式,如背景色:

.button{
   background-color: red;
 } 
或者只需将类添加到
并更改css中的样式


希望有帮助。

使用下面的
CSS
希望这对你有帮助

#select-choice-1 option:first-child, #select-choice-2 option:first-child {
     color: red;
}

按钮在哪里?你的jquery看起来也坏了,你在使用其他javascript库吗?更多信息和输入是我的按钮什么不起作用?您必须将“输入”按钮更改为您的ID。