Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript IE7/8中的jQuery动态元素错误_Javascript_Jquery_Internet Explorer - Fatal编程技术网

Javascript IE7/8中的jQuery动态元素错误

Javascript IE7/8中的jQuery动态元素错误,javascript,jquery,internet-explorer,Javascript,Jquery,Internet Explorer,在jQuery1.7.2中创建动态元素时,我发现这段代码在Safari、Chrome、Firefox和IE9/10中运行良好。但是,在IE7/8中,此代码会产生以下错误消息: SCRIPT1028:预期的标识符、字符串或数字 以下是元素创建代码: $("<span></span>", { text: "Please Specify: ", class: $(this).attr("id")+"other" <-- error points here

在jQuery1.7.2中创建动态元素时,我发现这段代码在Safari、Chrome、Firefox和IE9/10中运行良好。但是,在IE7/8中,此代码会产生以下错误消息:

SCRIPT1028:预期的标识符、字符串或数字

以下是元素创建代码:

$("<span></span>", {
    text: "Please Specify: ",
    class: $(this).attr("id")+"other" <-- error points here
});
$(“”{
文本:“请指定:”,
class:$(this).attr(“id”)+“other”因为在ECMAScript3(当前支持的版本是ES5)中,“class”是一个保留字,所以必须在属性名
class
周围添加引号,才能使其符合IE7/8。添加引号修复了这个问题,代码现在可以在我测试过的每个浏览器中使用

$("<span></span>", {
    text: "Please Specify: ",
    'class': $(this).attr("id")+"other"
});
$(“”{
文本:“请指定:”,
'class':$(this.attr(“id”)+“other”
});
因为在ECMAScript 3(当前支持的版本是ES5)中,“class”是一个保留字,您必须在属性名
class
周围添加引号,才能使其符合IE7/8。添加引号修复了这个问题,并且代码现在可以在我测试过的每个浏览器中运行

$("<span></span>", {
    text: "Please Specify: ",
    'class': $(this).attr("id")+"other"
});
$(“”{
文本:“请指定:”,
'class':$(this.attr(“id”)+“other”
});

请详细说明否决?!如果是因为重复,请告诉我们我会为谷歌保留它,因为它有更多的关键字。这是一个愚蠢的疏忽问题,也是一个重复。请详细说明否决?!如果是因为重复,请告诉我们我会为谷歌保留它,因为它有更多的关键字。这是一个愚蠢的疏忽问题和副本。