【发布时间】:2015-11-23 22:03:24
【问题描述】:
我这里有 4 个按钮,但只有第一个按钮可以工作,我希望相同的 jquery 代码稍作更改以在所有这些按钮上工作...... 我可以复制过去的 jquery 4 次并将其更改为工作,但我想要一个 jquery 更简单和更少的代码怎么做?
CSS
.yellowBackground {
background-color: yellow;
}
.redBackground {
background-color: red;
}
button.yellowBackground {
width:50px;
height:50px;
}
HTML
<table>
<tr>
<td><button id="button" class="yellowBackground">Pause</button></td>
<td><button id="button" class="yellowBackground">Pause</button></td>
<td><button id="button" class="yellowBackground">Pause</button></td>
<td><button id="button" class="yellowBackground">Pause</button></td>
</tr>
</table>
JS
$(function() {
$("#button").click(function() {
changeThumb();
});
});
function changeThumb() {
$("#button").toggleClass("redBackground");
}
【问题讨论】:
标签: jquery button colors size toggle