JQuery对class属性的操作实现按钮开关效果

 更新时间:2013年10月11日 16:57:38   作者:  
页面中的按钮开关效果想必大家都有见到过吧,接下来为大家详细介绍下如何使用JQuery对class属性的操作方法实现,感兴趣的朋友不要错过
在本文中用JQuery对class属性的操作方法实现页面中的按钮开关效果。

首先定义两个class:
复制代码 代码如下:

.controlOff{
display:inline-block;
width:130px;
height:36px;
cursor:pointer;
background-image:url("../iclass/images/teach_off.png");
background-repeat: no-repeat;
}

.controlOn{
display:inline-block;
width:130px;
height:36px;
cursor:pointer;
background-image:url("../iclass/images/teach_on.png");
background-repeat: no-repeat;
}

再定义一个超链接标签:
复制代码 代码如下:

<a href='javascript:void(0)' id='teachControl' class='controlOff'></a>

接着写JS脚本完成切换效果:
复制代码 代码如下:

function switchTeachControl(){
var target = $("#teachControl");
if(target.hasClass("controlOff")){
target.removeClass("controlOff");
target.addClass("controlOn");

}else{
target.removeClass("controlOn");
target.addClass("controlOff");

}
}

相关文章

最新评论