这是我的jQuery:
var skinCare=[];
$('.skinCare').click(function(){
if($.inArray(event.target.id, skinCare) == -1){
var value = event.target.id;
skinCare.push(value);
}
var index = skinCare.indexOf(value);
if($(this).css('background-color') == 'rgb(255, 255, 255)'){
skinCare.splice(skinCare.indexOf(index), 1);
}
});
$('html').click(function(){
alert(skinCare);
});
这是我显示供用户点击的 HTML:
<a href="#item4" class="panel"><div class="nextButton"></div></a>
<a href="#item3" class="panel multi"><div class="circle skinCare multi" id="acne" style="top:10px;left:265px"><div class="inner_circle" id="acne">ACNE/</br>BLEMISHES</div></div></a>
<a href="#item3" class="panel multi"><div class="circle skinCare multi" id="dry_skin" style="top:255px;left:10px"><div class="inner_circle" id="dry_skin">DRY SKIN</div></div></a>
<a href="#item3" class="panel multi"><div class="circle skinCare multi" id="oily_skin" style="top:90px;left:100px"><div class="inner_circle" id="oily_skin">OILY SKIN/LARGE PORES</div></div></a>
<a href="#item3" class="panel multi"><div class="circle skinCare multi" id="aging" style="top:90px;left:430px"><div class="inner_circle" id="aging">WRINKLES/</br>AGING</div></div></a>
<a href="#item3" class="panel multi"><div class="circle skinCare multi" id="irritation" style="top:255px;left:510px"><div class="inner_circle" id="irritation">SENSATIVE SKIN/IRRITATION</div></div></a>
<a href="#item3" class="panel multi"><div class="circle skinCare multi" id="dark_spots" style="top:430px;left:100px"><div class="inner_circle" id="dark_spots">DARK SPOTS</div></div></a>
现在我已经设置了 JQuery,因此如果单击的 div 的背景颜色是某种颜色(单击时由 css 类设置),它会在数组 skinCare 中添加或删除一个值。但是,我对任何可行的选项完全开放,并且不需要按颜色进行操作。如果单击 div,我只想将一个值添加到 JQuery 数组中,然后如果再次单击它,则将其从数组中删除。