参考文献:https://blog.csdn.net/u014101606/article/details/52318014
<ul id='mu2' style="display: flex;flex-wrap: wrap;margin: 10px;list-style: none;">
<li style="width: 18%;background-color: #F6F6F6;margin: 3px;text-align: center;padding: 2px;">xs
</li><li style="width: 18%;background-color: #F6F6F6;margin: 3px;text-align: center;padding: 2px;">xs
</li><li style="width: 18%;background-color: #F6F6F6;margin: 3px;text-align: center;padding: 2px;">xs
</li><li style="width: 18%;background-color: #F6F6F6;margin: 3px;text-align: center;padding: 2px;">xs
</li><li style="width: 18%;background-color: #F6F6F6;margin: 3px;text-align: center;padding: 2px;">xs
</li>
</ul>
document.getElementById("mu").onclick = function(e){
e = e || window.event;
var target = e.srcElement || e.target,
//tagName = target.tagName.toLowerCase(),
allLi = document.getElementById("mu").getElementsByTagName("li");
for(var i=0,len=allLi.length;i<len;i++){
if(target == allLi[i]){
allLi[i].style.backgroundColor = "red";
}else{
allLi[i].style.backgroundColor = "#EFEFF4";
}
}
};
网友评论