SCRIPT1028:预期的标识符,字符串或数字

时间:2012-10-01 14:49:14

标签: javascript internet-explorer

我正在运行一个显示事件日历的插件。它在所有浏览器中都很好用,除了IE兼容模式。选中该选项后,日历将消失。我相信它是一个JS错误。

IE调试器错误:

element.qtip({
    content: {
    text: event.description,
    title: {
    text: 'Description',
    }
  },
position: {
    at: 'top right',
    adjust: {
    x: 0, y: 30
   },
},

在我的插件编辑器中,这是代码:

element.qtip({
  content: {
  text: event.description,
  title: {
  text: '<?php _e('Description', 'event_espresso'); ?>',
  }
},
position: {
   at: 'top right',
   adjust: {
   x: 0, y: 30
  },
},

我不擅长调试,所以任何帮助都会受到赞赏。

如果有帮助,请点击以下页面:http://www.mbausa.org/calendar/

7 个答案:

答案 0 :(得分:44)

Internet Explorer在对象和数组中使用尾随逗号时遇到麻烦;

title: {
    text: 'Description', //<--
}

你可能想要:

title: {
    text: 'Description'
}

答案 1 :(得分:10)

此错误有两个常见原因。在不合适时使用尾随逗号或使用JavaScript保留字。在您的情况下,您有2个不必要的逗号。下面是正确的代码段,其中的注释用于删除逗号。

element.qtip({
  content: {
  text: event.description,
  title: {
    text: '<?php _e('Description', 'event_espresso'); ?>' // Removed Comma
  }
},
position: {
  at: 'top right',
  adjust: {
    x: 0, y: 30
  } // Removed Comma
},

我实际上做了一篇博客文章(和视频),解释了错误并展示了示例和修复。可在此处找到:http://mikemclin.net/fixing-error-script1028-expected-identifier-string-or-number/

答案 2 :(得分:8)

旧版本的IE不支持格式错误的JSON字符串。

当没有大括号'[',赞美'{'或新的对象属性后,你永远不应该使用逗号','分隔符。

尝试:

position: {
at: 'top right',
adjust: {
   x: 0, y: 30
  } // <-- no comma here
},

而不是:

position: {
at: 'top right',
adjust: {
   x: 0, y: 30
  }, // <-- comma here
},

答案 3 :(得分:3)

您可以强制使用非兼容模式...

,而不是在兼容模式下工作
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />

<head>标记中。

答案 4 :(得分:1)

另一个可能的错误是由于reserved关键字被用作哈希键。

IE8 errors when defining a Javascript object?

当我使用{class:'icon'}时,我也会收到此错误。其他IE8关键字可能也会这样做。

答案 5 :(得分:0)

如果您使用的是Vuex,并且问题出现在调用computed的{​​{1}}挂钩上,则问题出在散布运算符上。

mapState

使用babel修复它: https://babeljs.io/docs/en/babel-plugin-proposal-object-rest-spread

答案 6 :(得分:0)

尝试通过Babel或类似工具不进行转译而导入ES6模块时遇到此错误。

此行生成错误:

从“ my-npm-ES6-module”导入myES6module

解决方案是确保您的工作流确实将其转换为与浏览器兼容的JavaScript。

相关问题