繁体   English   中英

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

[英]Internet Explorer 9 in compatibility-mode shows error

在 IE 9 中测试我的 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。 我不明白。 jquery 源代码中有错误还是我的 js 文件中有错误? 我如何找到它?

自从我开始从事这个领域以来已经不久,所以请我真的很感激一些想法。

先感谢您。

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

我不知道要添加哪个部分。 整个代码不适合 stackoverflow 的提交。 说“正文限制为 3000 个字符;您输入了 42121”

[第二次编辑] 我在 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'})

它解决了我的问题。

感谢大家。

只是一个猜测,但是您是否在代码中的某个地方使用了 $.error() ? 如果是:不要使用它。


<edit>

但是,此错误来自jQuery.error()

原始错误函数如下所示:

error: function( msg ) {
        throw msg;
    }

您可以在没有 jquery 的情况下对其进行测试:

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

你会得到同样的错误。

如果你不使用jQuery.error()也许你使用了一些使用它的插件。 您可以通过在嵌入式 jquery.js 之后执行以下操作来覆盖此(错误?) function:

jQuery.error=function(){}

</edit>

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

jQuery.error() jQuery

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM