对象错误中的Javascript对象

时间:2012-12-11 00:42:36

标签: javascript object internet-explorer-8 internet-explorer-7

当我使用javascript对象时,我在Internet Explorer 7和8中有一个奇怪的错误。它适用于IE9和其他所有。

当我使用对象时,对象中的任何参数都是“类”,Internet Explorer 7和8停止做任何事情。

我正在使用jquery 1.8.2。

我会告诉你一些代码。

var obj = {
             data:{class:'image',action:'getAllFkId',type:nbType, fkid:id},
             success:function(json){
                alert('hi');

            }
        };
        this.ajax(obj);

“this.ajax”的代码(“this”是一个对象):

ajax : function(params){ 

        var defaults = {
            url: '../index.php',
            type:'POST',
            data:{},
            dataType:'json',
            success:function(){/*Function handler*/}
        }
        var options = $.extend(defaults, params);

        $.ajax(options);
        return this;
    }, // ..... rest of code

如果我将参数的名称更改为其他任何可用的名称。

// This is just fine foo instead of class
var obj = {
         data:{foo:'image',action:'getAllFkId',type:nbType, fkid:id},
         success:function(json){
            alert('hi');

        }
    };
    this.ajax(obj);

我想了解为什么IE7-8不能用“class”作为参数。 谢谢你的时间。

1 个答案:

答案 0 :(得分:2)

为了某些旧版浏览器,您需要将class括在引号中。

data:{"class":"image",...

虽然ECMAScript允许保留字作为属性标识符,但是一些旧版浏览器不允许使用它。