[英]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.