0
我没有最明智的想法,为什么这个函数只能工作一次..任何想法?jquery函数只能工作一次
var ColorsTable = ['red', 'green', 'blue', 'gold', 'white', 'black'];
var Rand = ColorsTable[Math.floor(Math.random() * ColorsTable.length)];
var Rand2 = ColorsTable[Math.floor(Math.random() * ColorsTable.length)];
jQuery(document).ready(function($) {
$('.losuj').click(function() {
$("#rama").css("background", Rand);
$("#rama2").css("background", Rand2);
var input = $('#wpis');
input.val('')
input.val(input.val() + Rand);
var input2 = $('#wpis2');
input2.val('')
input2.val(input2.val() + Rand2);
}); });
因为你在Rand'的'值传递,而不是每次运行时生成一个新的随机值。 –