×

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

作者:Terry2017.02.16来源:Web前端之家浏览:5372评论:0
关键词:JQueryJS
在本文中用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");

}
}

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/svg1487174400568.html

网友评论文明上网理性发言已有0人参与

发表评论: