时间:2021-07-01 10:21:17 帮助过:32人阅读
abc
看看这个是不是你要的结果:
var div = document.getElementById('div');var span = div.getElementsByTagName('span');for(var i = 0; i < span.length; i++){ span[i].onclick = function(){ if(this.className.length){ this.className = ''; } else { this.className = 'red'; } }}
test abc
看看这个是不是你要的结果:
var div = document.getElementById('div');var span = div.getElementsByTagName('span');for(var i = 0; i < span.length; i++){ span[i].onclick = function(){ if(this.className.length){ this.className = ''; } else { this.className = 'red'; } }}
test abc