pra*_*rai 51 wordpress jquery modal-dialog popup
我在我的WordPress网站上使用此链接的这个jquery弹出插件.它在所有浏览器上运行正常但在IE11上出现以下错误.
任何帮助深表感谢.
And*_*ich 104
正如其他人所提到的,IE中不支持Object.assign()方法,但有一个polyfill可用,只需在插件声明"之前"包含它:
if (typeof Object.assign != 'function') {
Object.assign = function(target) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
target = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source != null) {
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
}
Run Code Online (Sandbox Code Playgroud)
来自https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
测试页面:http://jsbin.com/pimixel/edit?html,js,output(只需删除polyfill即可获得您在页面上获得的相同错误).
根据文档,Object.assign()是一项新技术,是ECMAScript 2015(ES6)标准的一部分:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
它不受IE支持.
@John Doe
我从你的评论中想出你想在node/react堆栈中实现它.这与原始问题非常不同,你应该问自己;)
无论如何,你需要做什么......
您可以使用[es6-object-assign] [1].它是ES6 Object.assign()"polyfill".
首先,在package.json
根文件夹中,添加es6-object-assign
为依赖项:
"dependencies": {
"es6-object-assign": "^1.0.2",
"react": "^0.12.0",
...
},
Run Code Online (Sandbox Code Playgroud)
然后,如果要在节点环境中使用它:
require('es6-object-assign').polyfill();
Run Code Online (Sandbox Code Playgroud)
如果您在前面(浏览器)结束时遇到问题...
将其添加到index.html文件中...
<script src="location_of_node_modules/es6-object-assign/dist/object-assign.min.js"></script>
<script>
window.ObjectAssign.polyfill();
</script>
Run Code Online (Sandbox Code Playgroud)
location_of_node_modules
取决于你使用的样板,主要是node_modules
,但有时当index.html在你需要使用的子目录中时,../node_modules
当某些 html 元素 id 与 JavaScript 函数中的某些变量具有相同的 id 时,通常会发生这些错误。更改其中之一的名称后,代码起作用了。
其他链接:jquery 验证 IE 对象不支持属性