IE 11 Javascript 想要不需要的 ')'
IE 11 Javascript wants unneeded ')'
我在网站上的 IE 11 中有一个奇怪的行为...我在这段代码中收到控制台错误
function loadBasket (updated = false, buttonID = -1) {
$.ajax({
type: 'post',
url: azr_TemplateDir+'/ajax/page-basket.ajax.php',
success: function (data) {
$('.ajax-basket').html(data);
azrBinds();
},
complete: function (data) {
if(updated && buttonID >= 0) {
var button = $('div[data-buttonid="'+buttonID+'"]');
button.addClass('updated');
}
},
error : function(jqxhr,textStatus,error){
console.log(textStatus + ", " + error);
}
});
}
我的 IE 11 说它希望在第 1 行第 30 列有一个 ')',但那应该是在等号之后...Safari、Firefox、Chrome 和 Edge 不显示这个错误。
有没有人遇到过类似的问题?我很乐意提供帮助
谢谢
那是因为 IE 11 不支持默认值。
function loadBasket (updated, buttonID) {
updated = typeof updated === "undefined" ? false : updated;
buttonID = typeof buttonID === "undefined" ? -1 : buttonID;
// ...
IE 不支持默认参数。
改为使用此结构:
function loadBasket (updated, buttonID) {
updated = typeof updated !== 'undefined' ? updated : false;
buttonID = typeof buttonID !== 'undefined' ? buttonID : -1;
IE 不支持函数中的默认参数。
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Default_parameters
您必须手写默认值,例如:
function(a){
a = typeof a==="undefined" ? 6 : a;
}
我在网站上的 IE 11 中有一个奇怪的行为...我在这段代码中收到控制台错误
function loadBasket (updated = false, buttonID = -1) {
$.ajax({
type: 'post',
url: azr_TemplateDir+'/ajax/page-basket.ajax.php',
success: function (data) {
$('.ajax-basket').html(data);
azrBinds();
},
complete: function (data) {
if(updated && buttonID >= 0) {
var button = $('div[data-buttonid="'+buttonID+'"]');
button.addClass('updated');
}
},
error : function(jqxhr,textStatus,error){
console.log(textStatus + ", " + error);
}
});
}
我的 IE 11 说它希望在第 1 行第 30 列有一个 ')',但那应该是在等号之后...Safari、Firefox、Chrome 和 Edge 不显示这个错误。
有没有人遇到过类似的问题?我很乐意提供帮助
谢谢
那是因为 IE 11 不支持默认值。
function loadBasket (updated, buttonID) {
updated = typeof updated === "undefined" ? false : updated;
buttonID = typeof buttonID === "undefined" ? -1 : buttonID;
// ...
IE 不支持默认参数。
改为使用此结构:
function loadBasket (updated, buttonID) {
updated = typeof updated !== 'undefined' ? updated : false;
buttonID = typeof buttonID !== 'undefined' ? buttonID : -1;
IE 不支持函数中的默认参数。
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Default_parameters
您必须手写默认值,例如:
function(a){
a = typeof a==="undefined" ? 6 : a;
}