我试图检查span元素的活动状态和非活动状态。我在做网上电影票预订系统。因此,如果用户选择的座位,它应该改变为绿色。同样,用户也可以取消选择座位。所以,它应该变成旧的颜色。我试过一些..。贴在弹琴上。当我单击span元素时,它可以工作。但是,如何取消主动span元素的选择?
JsFiddle
Jquery
$(".active").click(function(){
$(this).css('background-color', 'green');
})CSS和HTML
<span class="active">seats</span>
.active
{
width: 100px;
height: 25px;
color: #000000;
background: #CCCCCC;
display: inline-block;
text-align: center;
}
.active
{
cursor: pointer;
}发布于 2014-02-05 10:51:42
创建一个切换类并应用toggleClass()
.green
{
background:green;
}
$( "span.active" ).click(function() {
$( this ).toggleClass( "green" );
});JSFIDDLE DEMO
发布于 2014-02-05 10:53:45
尝试脚本
$(".active").click(function(){
($(this).toggleClass('green_span');
})风格
.active
{
width: 100px;
height: 25px;
color: #000000;
background: #CCCCCC;
display: inline-block;
text-align: center;
}
.active
{
cursor: pointer;
}
.green_span{background:green}https://stackoverflow.com/questions/21575090
复制相似问题