twitter-bootstrap 如何使用 jquery 远程启用/禁用 Bootstrap 按钮?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19385107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 18:51:58  来源:igfitidea点击:

How to enable/disable Bootstrap buttons remotely using jquery?

javascriptjquerytwitter-bootstrap

提问by kyr

So I'm using Bootstrap for my project. Basically I want to have the Button disabled ("disabled" class) until the Click Count reaches a distinct number. JS Part:

所以我在我的项目中使用 Bootstrap。基本上我想禁用按钮(“禁用”类),直到点击计数达到一个不同的数字。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:

可选的 HTML 部分:

<p><a class="btn btn-primary btn-lg disabled" id="up1bt">Purchase: C100</a></p>

Any help?

有什么帮助吗?

回答by Arun P Johny

You have a spelling mistake up1btnand up1bt- The button id is up1btbut your selector is #up1btn, change the button id to up1btn.

您有拼写错误up1btn并且up1bt- 按钮 id 是up1bt但您的选择器是#up1btn,将按钮 id 更改为up1btn

Demo: Fiddle

演示:小提琴