var random = function(){ var a = 2; var n = Math.round(Math.random()*(a-1))+1; function obj(){ this.href = ''; this.class = ''; } b = new Array(); for (var i=1;i<=a;i++){ b[i] = new obj(); } b[1].href = "http://zgyxl.1905.com/"; b[1].class = "zgyxl-back2015"; b[2].href = "http://cinderella.1905.com/"; b[2].class = "hgn-back2014"; $('.link_l').add('.link_r').attr('href',b[n].href) $('body').removeClass().addClass(b[n].class); } random();