我正在使用Bootstrap进行我的项目。基本上,我希望在点击次数达到特定数字之前,按钮处于禁用状态("disabled"类)。 JS部分:
var timesClicked = 0; //main click variable
var CPC = 5;
var up1cost = 100; //cost for upgrade 1
function btnClick(){
timesClicked = timesClicked + CPC; //increases clicks by 1
$("#timesClicked").html(timesClicked) //parses over via jquery
if(timesClicked <= up1cost){
$("#up1btn").addClass("disabled")
} else {
$("#up1btn").removeClass("disabled")
}
return true;
}
Optional HTML Part:
<p><a class="btn btn-primary btn-lg disabled" id="up1bt">Purchase: C100</a></p>
有需要帮忙吗?
btnClick
? - Arun P Johny