嗨,有没有人能想出为什么这在Safari中不起作用?摘自奕江的代码。非常感谢
<div id="profile-list"></div>
<script>
var classes = ['email-checkout', 'absc', 'random', 'brrrr'];
for (var i = 0; i < 6000; i++) {
$('<input />').attr({
type: 'checkbox',
class: classes[Math.floor(Math.random() * classes.length)],
checked: (Math.random() > .5)
}).appendTo('#profile-list');
}
</script> 发布于 2010-12-09 19:46:30
class是一个保留字,您需要这样引用它:
"class": classes[Math.floor(Math.random() * classes.length)],我不确定这就是为什么Safari的failing...but it一定会因为这个原因在IE中失败的原因。
发布于 2010-12-09 19:46:39
我查看了开发人员控制台,它给出了一个解析错误,说明class是一个保留字。如果您将选项更改为被引用,则它将起作用:
for (var i = 0; i < 40; i++) {
$('<input />').attr({
"type": 'checkbox',
"class": classes[Math.floor(Math.random() * classes.length)],
"checked": (Math.random() > .5)
}).appendTo('#profile-list');
}https://stackoverflow.com/questions/4397804
复制相似问题