簡體   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