javascript IE 中的奇怪 jQuery 错误:对方法或属性访问的意外调用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8263069/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 02:49:56  来源:igfitidea点击:

Strange jQuery error in IE: Unexpected call to method or property access

phpjavascriptjqueryinternet-explorer

提问by Puzo

Like allways, in Firefox, Chrome, Safari and Opera everything works without a problem. But IE... This is another story :)

像往常一样,在 Firefox、Chrome、Safari 和 Opera 中一切正常。但是 IE ......这是另一个故事:)

Here is my full code: http://pastebin.com/ZdzzFayJ

这是我的完整代码:http: //pastebin.com/ZdzzFayJ

At least one thing good in IE, come to me with the following error:

至少在 IE 中有一件好事,来找我时出现以下错误:

SCRIPT65535: Unexpected call to method or property access. 
jquery.min.js, line 3 character 29586

What is wrong? I can't find a bug :(

怎么了?我找不到错误:(



UPDATE

更新

I cleaned up my code, javascript functions are now called as a jQuery plugin. I am still getting an error, but now I know where.

我清理了我的代码,javascript 函数现在被称为 jQuery 插件。我仍然遇到错误,但现在我知道在哪里了。

In my code I put a comment IE ERRORnext to the code where IE alert the error message.

在我的代码中,我IE ERROR在 IE 警告错误消息的代码旁边放了一条注释。

PLUGINS: http://pastebin.com/6Dnd1qtd

插件:http: //pastebin.com/6Dnd1qtd

jQuery : http://pastebin.com/wiHALjZx

jQuery:http: //pastebin.com/wiHALjZx

I have no idea why IE breaks there.. Any solutions?

我不知道为什么 IE 会在那里中断.. 任何解决方案?



Regards, Mario

问候, 马里奥

采纳答案by Puzo

I solved the problem in the following way:

我通过以下方式解决了这个问题:

  • Clean up my code ( JSHintwas very helpful! )
  • Before anything I included "//html5shiv.googlecode.com/svn/trunk/html5.js"to IE recognize that I am using HTML5 tags such as section, header,...
  • In jQuery plugin I fill element with html content. Instead of using $(defaultOpts.data_container).html("HTML CONTENT")I use defaultOpts.data_container.html("HTML CONTENT"). So I send object element $(#ID)in parameter to plugin instead of sending just element ID "#ID".
  • 清理我的代码(JSHint非常有帮助!)
  • 在我包含"//html5shiv.googlecode.com/svn/trunk/html5.js"到 IE 的任何内容之前,我认识到我正在使用 HTML5 标签,例如节、标题、...
  • 在 jQuery 插件中,我用 html 内容填充元素。而不是使用$(defaultOpts.data_container).html("HTML CONTENT")我使用defaultOpts.data_container.html("HTML CONTENT"). 因此,我将$(#ID)参数中的对象元素发送到插件,而不是仅发送元素 ID "#ID"

Now, everything working OK. Thank you all for your support and effort.

现在,一切正常。感谢大家的支持和努力。

回答by workdreamer

For me the problem was the following:

对我来说,问题如下:

i use a lib where is applied on all environment.

我在所有环境中使用了一个库。

my_lib.js

my_lib.js

jQuery.ajax({
        data : jQuery('form').serialize(),
        url : '/'+action[1]+'/post_form',
        type : 'POST',
        dataType: 'json',
        success: function(data){
            $('#my_name_id').find('option').remove().end().append(data.select_options);

});

Json returns:

杰森返回:

select_options  "<option></option>"

Everything is fine! BUT, in one form #my_name_id is not a select, is a hidden field, it's a pre-selected value and disabled attribute for the user.

一切都好!但是,在一种形式中,#my_name_id 不是选择,而是隐藏字段,它是用户的预选值和禁用属性。

That's why jquery on IE8 retrieves me the error.

这就是 IE8 上的 jquery 为我检索错误的原因。

The solution was:

解决方案是:

my_lib.js

my_lib.js

jQuery.ajax({
        data : jQuery('form').serialize(),
        url : '/'+action[1]+'/post_form',
        type : 'POST',
        dataType: 'json',
        success: function(data){
          if( $('#my_name_id').is('select') ) {
             $('#my_name_id').find('option').remove().end().append(data.select_options);
          }
});

Hope it helps somebody!

希望它可以帮助某人!

回答by lsuarez

You appear to be missing a semi-colon in your get_data function after echo_data(data).

您的 get_data 函数中似乎在echo_data(data).

request.done(function(data) {
    if (data) echo_data(data) _loading.hide();
    _ads_listing.unmask();
});