捷弘和宇乐两个按钮,在点击选中时颜色做区分
点击捷弘按钮,捷弘按钮颜色改变;点击宇乐按钮,宇乐按钮颜色改变,捷弘按钮颜色恢复
如图:
html代码:
<a id="jiehong" class="btn btn-warning" οnclick="createList(yearStr,monthStr,'捷弘')"> <i class="fa fa-download"></i> 捷弘 </a> <a id="yule" class="btn btn-warning" οnclick="createList(yearStr,monthStr,'宇乐')"> <i class="fa fa-download"></i> 宇乐 </a>
function createList(year, month, name) { let jiehong = document.getElementById("jiehong"); let yule = document.getElementById("yule"); if(name==='捷弘'){ jiehong.style.backgroundColor="#0000ff"; yule.style.backgroundColor="#f89406"; }else if(name==='宇乐'){ yule.style.backgroundColor="#0000ff"; jiehong.style.backgroundColor="#f89406"; }}