Internet Explorer 9在兼容模式下显示错误

Internet Explorer 9 in compatibility-mode shows error

本文关键字:模式 显示 错误 Explorer Internet      更新时间:2023-09-26

在ie9中测试我的jQuery脚本时,它显示jQuery -1.6.2.js——

SCRIPT5022: Exception thrown and not caught 
jquery-1.6.2.js, line 548 character 3

我的js文件以前在其他浏览器上运行没有问题——firefox 3.6, 5.0, opera 11, chromium, chrome。我不明白。是否有一个bug在jquery源或有一个bug在我的js文件?我怎么找到它?

我在这个领域工作没多久,所以请给我一些建议。

提前谢谢你。

[编辑]我已经添加了完整的代码。我学到的是:http://net.tutsplus.com/tutorials/javascript-ajax/how-to-create-a-jquery-image-cropping-plug-in-from-scratch-part-ii/

我不知道该添加哪一部分,整个代码不适合stackoverflow的提交。表示"正文限制为3000个字符;您输入了42121 "

(第二编辑)我已经使用'error'在我的ajax提交。

    //jquery ajax submit for resizing
    function submit(myform,e){
        $n.val($image.attr('src').replace(/^[^,]*'//,''));
        var mydata = myform.serialize();
        $.ajax({
            url: $myform.attr('action'),
            cache: false,
            type:$myform.attr('method'),
            data: mydata,
            success: function(response){
                var img = $("<img />").attr('src', 'images/'+response+'?'+ e.timeStamp) //<-- img name here
                    .load(function() {
                       if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
                           alert('Incorrect image.');
                       } else {
                           $("#result").html(img); //<-- put cropped img here.
                       }
                    });

                    },
            error: function(){ //<-- error used here
                        $('#result').html("Err. Loading Image");
                    }
        });
    };

我找到了我的问题。IE阻止更改属性,这会导致jQuery错误。

 Note: jQuery prohibits changing the type attribute on an or element and
 will throw an error in all browsers. This is because the type attribute 
 cannot be changed in Internet Explorer." 

来自http://api.jquery.com/attr,就在第一个警告通知之后。

所以我改变了前面的代码

$('input').clone() 

$('<input />').attr({'type':'hidden'})

它解决了我的问题。

谢谢大家。

jQuery.error()(其中throws作为消息传递的参数)与AJAX调用中指定的error处理程序完全不同。

jQuery.error()jQuery内部使用(搜索"error("))。你应该调试你的代码,并按照堆栈跟踪,找出你的哪个方法调用jQuery方法是错误的。

只是猜测,但是您是否在代码中某处使用了$.error() ?如果是:请不要使用。


<edit>

但是,这个错误来自jQuery.error()。

原来的error-function是这样的:

error: function( msg ) {
        throw msg;
    }

你可以不使用jquery进行测试:

(function( msg ) {
        throw msg;
    })('errormessage');

你会得到相同的错误。

如果你不使用jQuery.error()也许你使用一些插件使用它。你可以通过在嵌入的jquery.js之后执行以下命令来覆盖这个(有bug的?)函数:

jQuery.error=function(){}
</edit>