Javascript 数组中属性的Push值

Javascript 数组中属性的Push值,javascript,jquery,html,arrays,Javascript,Jquery,Html,Arrays,$(文档).ready(函数(){ 函数randomColor(){ 返回'rgb'('+ Math.round(Math.random()*255)+','+ Math.round(Math.random()*255)+','+ Math.round(Math.random()*255)+') } $('.Showcolor#按钮')。每个(功能(i){ $(this.css('background-color',randomColor()); }) var Random=[]; var co

$(文档).ready(函数(){
函数randomColor(){
返回'rgb'('+
Math.round(Math.random()*255)+','+
Math.round(Math.random()*255)+','+
Math.round(Math.random()*255)+')
}
$('.Showcolor#按钮')。每个(功能(i){
$(this.css('background-color',randomColor());
})
var Random=[];
var color=$(“.Showcolor#button”).css(“背景色”);
对于(i=0;i

验证码
单击与右圆匹配的圆

修复ID。而不是

$('.Showcolor #button').each(function(i) {
         $(this).css('background-color', randomColor());
      })
使用


要选择
Showcolor

下的所有
元素,首先
id
属性在同一文档中必须是唯一的,因此用公共类替换重复的元素,如:

<button class="button Black">Black</button>
<button class="button Blue">Blue</button>
<button class="button Orange">Orange</button>

单击与右圆匹配的圆
黑色
蓝色
橙色
粉红色
紫色
天蓝色
棕色的

随机的
一个文档中具有相同ID的多个元素是无效的HTML。首先解决这个问题。好的,那么jqueryIt在使用jQuery时也是无效的。另外,变量名(例如,
var Random=[];
按惯例应该是小写的,以避免混淆。
<button class="button Black">Black</button>
<button class="button Blue">Blue</button>
<button class="button Orange">Orange</button>