当前位置: 移动技术网 > IT编程>开发语言>JavaScript > JQuery对class属性的操作实现按钮开关效果

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

2018年11月30日  | 移动技术网IT编程  | 我要评论

在本文中用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");

}
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网