我試圖在點擊按鈕時改變按鈕的類別。爲什麼不是我的工作: 看到我fiddle按鈕不起作用的簡單onclick功能
HTML:
<button id="repeatMon" onclick="changeStyle()"><span> Mon </span></button>
<br/>
<button id="repeatTues" data-bind="checked: repeatTues" onclick="changeStyle()"><span> Tues </span></button>
<br/>
<button id="repeatWeds" data-bind="checked: repeatWeds" onclick="changeStyle()"><span> Weds </span></button>
<br/>
<button id="repeatThurs" data-bind="checked: repeatThurs" onclick="changeStyle()"><span> Thurs </span></button>
<br/>
<button id="repeatFri" data-bind="checked: repeatFri" onclick="changeStyle()"><span> Fri </span></button>
<br/>
<button id="repeatSat" data-bind="checked: repeatSat" onclick="changeStyle()"><span> Sat </span></button>
<br/>
<button id="repeatSun" data-bind="checked: repeatSun" onclick="changeStyle()"><span> Sun </span></button>
<br/>
CSS:
button{
width: 60px;
height: 35px;
border-radius: 0px;
color: #cfcfcf;
background: #0a4a58;
}
.active{
color: #fff;
background: ##02AEFF;
}
的jQuery:
function changeStyle(){
$(this).toggleClass('active');
}
謝謝!
'onclick =「changeStyle(this)」'? – Antony 2013-02-15 14:02:20