在本文中以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; cursor:pointer;
background-image:url("../iclass/images/teach_on.png");
background-repeat: no-repeat;
}
再定義一個超鏈接標籤:
接著寫入JS腳本完成切換效果:
function switchTeachControl(){
var gets = $( ");
if(target.hasClass("controlOff")){
target.removeClass("controlOff");
target.addClass("controlOn");
target.addClass("controlOn");
}else {
target.removeClass("controlOn");
target.addClass("controlOff");
}
}