我只在 IE8 中遇到奇怪的错误,在 IE9 中没有。错误信息是:
SCRIPT1028: Expected identifier, string or number
这是我的标记:
<style>
.warrior { color: red; }
.ninja { color: blue; }
.wizard { color: green; }
</style>
<div id="player"></div>
<script src="Scripts/jquery.min.js"></script>
<script>
(function () {
"use strict";
var joeBlow = {
name: "Joe Blow",
class: "ninja",
age: 35
};
$("#player").html(joeBlow.name + " " + joeBlow.age).addClass(joeBlow.class);
}());
</script>
我的期望是 DIV
会用蓝色写“Joe Blow 35”,但我收到了上面的错误。
是什么导致在 IE8 中发生这种情况,但在 IE9 或 IE10 中却没有?
最佳答案
class
是保留关键字。在它周围加上引号 'class'
。您可能还必须使用 []
表示法访问该属性,如 joeBlow['class']
中所示。
关于javascript - 使用 jQuery 时出现奇怪的 IE8 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18926841/