简体   繁体   English

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

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

When you run the code and press the plan pack button, you could still press the spaceship button. 当您运行代码并按计划包按钮时,仍然可以按太空飞船按钮。 Here is the code. 这是代码。

HTML: 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: 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);
}
}

Never mind, I fixed it. 没关系,我已修复它。

var money = 10000;

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

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

Use an if statement to set your condition then use .prop() to disable the button, try giving your button an id so you can select it. 使用if语句设置条件,然后使用.prop()禁用按钮,并尝试为按钮指定一个ID,以便可以选择它。

Try this I think it will help you. 试试这个,我认为它将为您提供帮助。

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

$money is a variable of the I think you can output this using php, mysql $ money是我的变量,我认为您可以使用php,mysql输出

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

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