下面小编就为大家带来一篇jquery点击切换背景色的简单实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。
不说了,上代码:
.box {
width: 100px;
height: 100px;
margin: 0;
background-color: red;
}
$(document).ready(function(){
var colorArr = ['white','red'];
var count = 0;
$('.box').click(function() {
var $this = $(this);
$this.css('backgroundColor', colorArr[count%2]);
count++;
});
});
以上这篇jquery点击切换背景色的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考