Javascript 未定义函数参数
为什么我的爱人不工作Javascript 未定义函数参数,javascript,Javascript,为什么我的爱人不工作 function myFunc(e){ e = e || 'add' || 'remove'; document.body.classList.e('hide'); } myFunc(remove); myFunc(add); 如果你想这么做的话 function spinner(e){ let $spinner = document.querySelector('.isolador_spinner'); if ( e ===
function myFunc(e){
e = e || 'add' || 'remove';
document.body.classList.e('hide');
}
myFunc(remove);
myFunc(add);
如果你想这么做的话
function spinner(e){
let $spinner = document.querySelector('.isolador_spinner');
if ( e === 'remove' ){
$spinner.classList.remove('hideSpinner');
} else if ( e === 'add' ) {
$spinner.classList.add('hideSpinner');
} else {
console.log('e was not defined');
}
}
它声称e不是通过间接变量访问对象属性的函数,请使用: 我还建议对参数使用
e
以外的名称。在JavaScript中,名为e
的函数参数通常意味着e
是一个函数。称之为action
可能是更好的选择
您在编辑中添加的代码也有问题:
myFunc(remove); // wrong - remove is not a variable
myFunc('remove'); // correct
它声称e不是一个函数。对我来说,这种说法似乎是正确的!所以这是不可能的?你想做什么?我不知道你想做什么。如果你尝试根据指导原则编辑你的问题,其他人会更容易理解代码>
myFunc(remove); // wrong - remove is not a variable
myFunc('remove'); // correct