我对Javascript/jQuery的了解很少,所以不确定这是如何容易修复…我有下面的脚本切换4个隐藏的div在单独的页面底部,它工作得很好,除了在Internet Explorer (IE 11)。
调试器显示"jQuery。延迟异常:对象不支持属性或方法'assign' TypeError:对象不支持属性或方法'assign'",我的脚本有Object。在里面赋值。我只是想知道有没有人知道另一种解决方案?
我的代码如下:
(function($) {
jQuery(document).ready(function() {
var panel1 = new Panel(1),
panel2 = new Panel(2); panel3 = new Panel(3); panel4 = new Panel(4);
$(document).on('click', '.tab-controller1', function() {
panel1.togglePanel();
});
$(document).on('click', '.tab-controller2', function() {
panel2.togglePanel();
}); $(document).on('click', '.tab-controller3', function() {
panel3.togglePanel();
}); $(document).on('click', '.tab-controller4', function() {
panel4.togglePanel();
});
});
// Constructor. Needs to get the number 1 or 2
function Panel(num) {
var that = this; // Remember the object that is created here
Object.assign(that, {
isVisible : false,
showMessage : null,
hideMessage : null,
animationDuration : 300,
animationEasing : 'linear',
init: function() {
that.hidePanel();
},
hidePanel : function() {
// Use number to address the correct class, here and below.
$('.infoToggle' + num).animate({
bottom : -(that.getAnimationOffset())
}, that.animationDuration, that.animationEasing, function() {
that.isVisible = false;
that.updateTabMessage();
});
},
showPanel : function() {
$('.infoToggle' + num).animate({
bottom : 0
}, that.animationDuration, that.animationEasing, function() {
that.isVisible = true;
that.updateTabMessage();
});
},
togglePanel : function() {
(that.isVisible ? that.hidePanel : that.showPanel)();
},
updateTabMessage : function() {
if (that.isVisible) {
$('.tab-controller' + num + ' .close').show();
$('.tab-controller' + num + ' .show').hide();
} else {
$('.tab-controller' + num + ' .close').hide();
$('.tab-controller' + num + ' .show').show();
}
},
getAnimationOffset : function() {
return $('.panel-content' + num).height();
}
});
// call init here, which will execute when you do `new Panel`:
that.init();
} })(jQuery);
如果您对项目使用编译,则快速解决方案。您可以考虑在入口点的顶部添加
import 'core-js'
目前core-js polyfill库是实现跨浏览器支持最简单的方法