我收到了这个错误:
未捕获的TypeError:无法读取HTMLTableCellElement.toto中未定义的属性“toggle”
有人可以帮忙吗?
var comments = document.getElementsByClassName('organisation');
var numComments = comments.length;
function toto(e){
/*this.style.cssText='background-color:white';*/
comments.classList.toggle('.maClasse');
}
for (var i = 0; i < numComments; i += 1) {
comments[i].addEventListener('click', toto, false);
}
答案 0 :(得分:0)
很好!
var comments = document.getElementsByClassName('organisation');
var numComments = comments.length;
//function toto(e){
//this.style.cssText='background-color:white';
//comments.classList.toggle('.maClasse')
function myFunction() {
this.classList.toggle("maClasse");
};
//}
for (var i = 0; i < numComments; i += 1) {
comments[i].addEventListener('click', myFunction, false);
}