解决方法
var link = []; link[0] = "http://site.com/css/style1.css"; link[1] = "http://site.com/css/style2.css"; link[2] = "http://site.com/css/style3.css"; $(function() { var style = link[Math.floor(Math.random() * link.length )]; $('<link />',{ rel :'stylesheet',type:'text/css',href: style }).appendTo('head'); });
编辑:谢谢Basil Siddiqui!
var link = []; link[0] = "http://site.com/css/style1.css"; link[1] = "http://site.com/css/style2.css"; link[2] = "http://site.com/css/style3.css"; $(function() { var style = link[Math.floor(Math.random() * link.length )]; if (document.createStyleSheet){ document.createStyleSheet(style); }else{ $('<link />',{ rel :'stylesheet',href: style }).appendTo('head'); } });