function randomColor() { //16进制方式表示颜色0-F var arrHex = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"]; var strHex = "#"; var index; for(var i = 0; i < 6; i++) { //取得0-15之间的随机整数 index = Math.round(Math.random() * 15); strHex += arrHex[index]; } return strHex; } function changeColor(){ var links = $('#tip_bgColor span'); for(var i=0;i<links.length;i++){ var bgColor = randomColor();//改变背景色的代码, links[i].style.backgroundColor = bgColor; } } changeColor(); $('.next_eff').click(function(){ changeColor(); })