0
为什么addEventListener
与function()
在注释的代码中一起使用,但没有通过特定的功能?为什么addEventListener与函数()一起工作,但没有使用我传递的特定函数?
var button = document.querySelector("button");
// button.addEventListener("click", function(){
// button.classList.toggle("bigyellow");
// });
button.addEventListener("click", toggleMe);
function toggleMe(){
this.classList.toggle("big-yellow");
}
//CSS:
//.bigyellow {
// background-color: #ffff66; /* yellow */
//}
工作正常,我....但是,你就引用它,而不是依赖于吊装前,真的应该声明你的函数。 – epascarello
@Cruiser - 'this'里面'toggleMe' *应该*是点击的按钮 –
哦亲爱的......'toggle(“bigyellow”);'!=='toggle(“big-yellow”);'' –