单击按钮会更改其他div的背景颜色?

时间:2014-02-16 01:07:11

标签: javascript html button colors background

  $(document).ready(function() {
  $('#button').click(function() {
  var colors = ["#16A085","#2980b9","#34495e"]  
  var rand = Math.floor(Math.random()*colors.length);           
  $('.navbar-inverse').css("background-color", colors[rand]);

});

错误是什么?我希望在单击#button时更改.navbar-inverse的背景颜色。

1 个答案:

答案 0 :(得分:0)

$(document).ready(function() {
    $('#button').click(function() {
        var colors = ["#16A085","#2980b9","#34495e"]; // here
        var rand = Math.floor(Math.random()*colors.length);           
        $('.navbar-inverse').css("background-color", colors[rand]);
    }); // here
});
  1. 在3.行
  2. 结尾处缺少分号
  3. 缺少“});”在点击回调结束时