繁体   English   中英

如果资金不足2900,您如何确保不能再次按下两个按钮?

[英]How would you make sure that you can't press both the buttons again if the money is under 2900?

当您运行代码并按计划包按钮时,仍然可以按太空飞船按钮。 这是代码。

HTML:

<fieldset>
  <legend>Store</legend>
<p id="p"></p>
Spaceship: $2900
   <input type="button" value="Buy" onClick="buy()" id="button" /><br />
Plan pack: $7800
<input type="button" value="Buy" onClick="buy1()" id="button1" /><br />
     </fieldset>

JS:

var money = 10000;
function buy()  {
money = money - 2900;
$("#p").text("You have $" + money + ".");
if(money < 2900){
$("#button").prop("disabled", true);
}
}
function buy1() {
money = money - 7800;
$("#p").text("You have $" + money + ".");
if(money < 7800){
        $("#button1").prop("disabled", true);
}
}

没关系,我已修复它。

var money = 10000;

if(money < 2900){
 $( "#Your_button" ).prop( "disabled", true );
}

function buy() {
money = money - 2900;
$("#p").text("You have $" + money + ".");
}

使用if语句设置条件,然后使用.prop()禁用按钮,并尝试为按钮指定一个ID,以便可以选择它。

试试这个,我认为它将为您提供帮助。

if($money < 2900){
 $("#button").attr("disabled","disabled");
 }

$ money是我的变量,我认为您可以使用php,mysql输出

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM