翻看html5 classList API:
myDiv.classList.add('myCssClass'); // 添加 class
myDiv.classList.remove('myCssClass'); // 移除 class
myDiv.classList.toggle('myCssClass'); // 切换 class
直接上代码吧:
<ul id="runner_list" class="runner_list">
<li id="runner1" class="runner">1</li>
<li id="runner2" class="runner">2</li>
<li id="runner3" class="runner">3</li>
<li id="runner4" class="runner">4</li>
</ul>
window.onload=function(){
var runnerList=document.getElementById("runner_list"),
btnGo=document.getElementById("go"),
btnReady=document.getElementById("ready"),
runnerArr=Array.prototype.slice.call(runnerList.querySelectorAll("li"));
btnGo.onclick=function(){
runnerArr.forEach(function(i){
i.classList.add('go');
});
};
}