我怎么知道如下例所示,哪个事件用于触发函数?
function setSize() {
if() { // event == 'load'
console.log("Loaded");
} else if() { // event == 'resize'
console.log("Resized");
}
}
window.addEventListener('load', setSize, false);
window.addEventListener('resize', setSize, false);
感谢。
答案 0 :(得分:3)
function setSize(event) {
if(event.type == 'load') { // event == 'load'
console.log("Loaded");
} else if(event.type == 'resize') { // event == 'resize'
console.log("Resized");
}
}
window.addEventListener('load',function(){setSize(event)},false);
window.addEventListener('resize',function(){setSize(event)},false);
window.addEventListener('load', setSize, false);
window.addEventListener('resize', setSize, false);