如何更改按钮的颜色?

时间:2016-01-06 17:19:34

标签: javascript jquery html5

如何更改"输入"以及"更多信息"按钮这是我的脚本:

$(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());


    });    

});

非常适合帮助

3 个答案:

答案 0 :(得分:0)

页面的控制台中尝试此操作,您将转过&#34;发布您的答案&#34;按钮的颜色......

$("#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类:&#34; .button-color&#34; 基于ID:&#34;#my-button&#34; 基于ELEMENT:&#34;:按钮&#34;

答案 1 :(得分:0)

不是分配给&lt;'option'&gt;而是创建一个类并分配给类名,如下所示:

$( ".button" ).append( "what you want" );

然后在你的CSS中你可以改变按钮的样式,比如背景颜色:

.button{
   background-color: red;
 } 

或者只需将课程添加到<option>并更改css中的样式。

希望它有所帮助。

答案 2 :(得分:0)

使用以下CSS希望这会对您有所帮助。

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