我试图从jQuery中预设的列表中随机添加一个类到一个元素,例如
可用课程:Theme1,Theme2,Theme3
var NumClasses = 3
function randOrd() {
return (Math.round(Math.random())-0.NumClasses);
}
$(document).ready(function() {
var klasses = [ 'Theme1', 'Theme2', 'Theme3' ];
klasses.sort( randOrd );
$("#main-body-header").addClass(klasses[i]);
});