【问题标题】:IE 8, object required javascript functionIE 8,对象需要 javascript 函数
【发布时间】:2010-08-12 14:31:30
【问题描述】:

我整天都在寻找我的奇怪问题。

我有一个页面,它通过 ajax(使用 jQuery)动态加载内容,但我认为这不是 jQuery 问题。

动态页面包含一个javascript函数,我们称之为“myTestFunction()”,不带任何参数。

在 document.ready (jQuery) 之后或页面末尾,我调用了这个函数。 Firefox 运行此功能。 IE 8 说:需要对象。我认为IE找不到该功能。

我对这个 IE 消息感到很困惑。我希望有人对此有所了解。如何告诉 IE 函数在哪里?

最诚挚的问候,非常感谢您的回答。 !!!!这段代码解释了问题,运行未测试,但我希望它应该描述问题。很抱歉奇怪的“代码格式,这是我在这个编辑器中的第一个代码示例”。

 //example of code, a code like this is loaded by our Framework with ajax in a div. 
 <?      //myclass generates the HTML-Output, and generates the Function
         //myTestFunction in an JavaScript Tag see below 
         $myClass = new MyClass('127.0.0.1/application/file.php');
         echo $myClass->renderHTMLcode();
 ?>

<script>
  // alert 1 for me for testing.    
  alert('ende');
 $(document).ready(function() {
     // alert 2, for me , ready event of jQuery has fired  
     alert('ready');
     // function with the problem
      myTestFunction(); 
             }
    );
   <script>        
函数 myTestFunction() { alert('fromTest'); } ///... } } ?>

【问题讨论】:

  • 请发布您的代码,以便我们了解您是如何定义和调用该函数的。
  • 需要更多信息。能否请您发布您的页面代码。
  • -1 演示您的问题的最小测试用例怎么样?
  • IE 的错误消息在告诉您真正的问题时完全是垃圾。您的函数可能会被调用,但其中的某些内容正在尝试访问 IE 中不存在的对象。

标签: javascript jquery ajax internet-explorer-8


【解决方案1】:

你应该使用 window.myTestFunction()

但这是一个非常奇怪的错误,即给你。也许你应该看看this

【讨论】:

  • 如果myTestFunction() 给出一个"Object expected" 错误,那么window.myTestFunction() 在这里将无济于事。唯一有用的情况是局部变量覆盖全局函数 - 但其他浏览器(如 Firefox)也是如此。
猜你喜欢
  • 2017-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多