使用jquery从数组中获取要编辑的随机值.css
我试图让边框颜色在每次单击按钮时从数组中更改为随机颜色,但它只从数组中为边框颜色选择一次随机颜色,而不会在每次单击按钮时更改为随机颜色使用jquery从数组中获取要编辑的随机值.css,jquery,css,arrays,Jquery,Css,Arrays,我试图让边框颜色在每次单击按钮时从数组中更改为随机颜色,但它只从数组中为边框颜色选择一次随机颜色,而不会在每次单击按钮时更改为随机颜色 $(document).ready(function () { 'use strict'; var nextBtnClicks = 0, previousBtnClicks = 0, colors = ['#ff0000', '#00ff00', '#0000ff'], random_color =
$(document).ready(function () {
'use strict';
var nextBtnClicks = 0,
previousBtnClicks = 0,
colors = ['#ff0000', '#00ff00', '#0000ff'],
random_color = colors[Math.floor(Math.random() * colors.length)];
$('#NxtBtn').click(function () {
if (nextBtnClicks < 8) {
$('#image').animate({left: '-=640px'}, 500, function () {
$('#pic_box').css('border-color', random_color);
});
nextBtnClicks += 1;
} else {
$('#image').animate({left: '0px'}, 500);
nextBtnClicks = 0;
}
});
});
$(文档).ready(函数(){
"严格使用",;
var nextbttnclicks=0,
以前的BTNClicks=0,
颜色=['#ff0000'、'#00ff00'、'#0000ff'],
random_color=colors[Math.floor(Math.random()*colors.length)];
$('#NxtBtn')。单击(函数(){
如果(下一个<8){
$('#image')。动画({left:'-=640px'},500,函数(){
$('pic#u box').css('border-color',random_color);
});
nextbttnclicks+=1;
}否则{
$('#image')。设置动画({left:'0px'},500);
nextbttnclicks=0;
}
});
});
您可以在click函数之外设置random_color变量,这样它就可以设置并保持不变。将该行移到。单击函数