【问题标题】:IE Error TypeError: Unable to get value of the property 'set': object is null or undefinedIE 错误类型错误:无法获取属性“设置”的值:对象为空或未定义
【发布时间】:2015-05-09 20:03:33
【问题描述】:

当我在 IE9 中运行我的 Web 应用程序时出现以下错误。该应用程序正在使用 StrutsDOJO UI

开发控制台正在显示:

TypeError: Unable to get value of the property 'set': object is null or undefined 

在 FF 或其他浏览器中不会出现此错误。我已经查看了此问题的其他解决方案,但似乎没有一个可以解决我的问题。

我尝试过在我的网页头部使用标签:

<meta http-equiv="X-UA-Compatible" content="IE=edge">

失败的 JavaScript:

require(["dojo/on", "dojo/dom", "dojo/_base/lang", "dojo/domReady!", "dojo/query","dijit/registry"],
  function (on, dom, lang, query) {

    $(document).ready(function () { 

      var addButton = dijit.byId('addName');

      if(addButton){
          addButton.on('click', function (evt) {
              evt.preventDefault();
              grid.addRecord('name');

            });       
      }
});

【问题讨论】:

  • $(document) 语法参考 jquery。您是否也在使用 Jquery。要在 dojo 中使用 ready(),您需要像 dojo/ready 这样的 dojo 就绪模块。 dojo/domReadydojo/ready 不同。 domReady 应该在最后。此外,您需要的模块与回调中的参数不匹配。

标签: javascript jquery web struts2 dojo


【解决方案1】:

进行以下更改,您应该一切顺利。

 // Moved dojo/domReady! at the end. Added dojo/ready module.
 require(["dojo/on", "dojo/dom", "dojo/_base/lang", "dojo/ready", "dojo/query","dijit/registry", "dojo/domReady!" ],
  // The callback list below should match the modules in the require statement.
  function (on, dom, lang, ready, query, registry) {

    // $(document) refers to Jquery plugin. Are you using Jquery
    //$(document).ready(function () { 
    ready(function () {    //  using the dojo/ready module.

      // changed dijit to registry
      //var addButton = dijit.byId('addName'); 
      var addButton = registry.byId('addName');

      if(addButton){
          addButton.on('click', function (evt) {
              evt.preventDefault();
              grid.addRecord('name');

            });       
      }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-30
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多