gpt4 book ai didi

javascript - 使用 javascript 禁用 HTML 中的按钮

转载 作者:行者123 更新时间:2023-11-28 19:21:49 28 4
gpt4 key购买 nike

在我的游戏中,玩家有一个余额,当他们单击按钮时,余额会减少 5000,当达到 0 时,他们会从 20,000 开始,我希望出现一个警报(我已经正常工作了),并且按钮是禁用 - 我无法让它工作,有人可以透露一些信息吗?所有功能都运行良好,顺便说一句,我只是想将禁用按钮添加到“减去”功能 - 谢谢!

这是我正在使用的代码

<script type="text/javascript">
function subtract() {

var Balance = document.getElementById("Balance");
var Fee = parseInt(Balance.value) - 5000;
Balance.value = Fee;

if(Fee <= 0){
alert("To Continue Playing - Purchase More Coins at - LINK");
}
}
</script>


<button class="randombutton" id="aaa" style="float:left;" onclick= "
randomImg1();
randomImg2();
randomImg3();
randomImg4();
randomImg5();
randomImg6();
randomImg7();
randomImg8();
subtract();
foo(this);"/>OPEN PACK</button>

最佳答案

要使用 javascript 禁用表单元素,请设置 disabled属性设置为true

function subtract() {

var Balance = document.getElementById("Balance");
var Fee = parseInt(Balance.value) - 5000;
Balance.value = Fee;

if(Fee <= 0){
// Get the element and then set the disabled property to true.
document.getElementById('aaa').disabled = true;

alert("To Continue Playing - Purchase More Coins at - LINK");
}
}

关于javascript - 使用 javascript 禁用 HTML 中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28708360/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com