Jquery无法在Safari中工作

嗨,任何人都可以解决为什么这在Safari中不起作用? 它取自易江的代码。 非常感谢

var classes = ['email-checkout', 'absc', 'random', 'brrrr']; for (var i = 0; i < 6000; i++) { $('').attr({ type: 'checkbox', class: classes[Math.floor(Math.random() * classes.length)], checked: (Math.random() > .5) }).appendTo('#profile-list'); }

class是保留字,你需要像这样引用它:

 "class": classes[Math.floor(Math.random() * classes.length)], 

不确定这就是Safari失败的原因……但是因为这个原因,IE肯定会失败。

我查看了开发人员控制台,它给出了一个解析错误, class是一个保留字。 如果您更改要引用的选项,则它可以正常工作:

 for (var i = 0; i < 40; i++) { $('').attr({ "type": 'checkbox', "class": classes[Math.floor(Math.random() * classes.length)], "checked": (Math.random() > .5) }).appendTo('#profile-list'); }