使用 javascript 禁用 HTML 中的按钮
Disabling a button in HTML using javascript
在我的游戏中,玩家有一个余额,当他们点击按钮时,余额下降 5000,当他们达到 0 时,他们从 20,000 开始,我想要一个警报出现(我有那个工作)和按钮被禁用 - 我无法让它工作,任何人都可以解释一下吗?所有功能都运行良好,顺便说一句,我只是想在 "Subtract" 功能中添加禁用按钮 - 谢谢!
这是我正在使用的代码
<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");
}
}
在我的游戏中,玩家有一个余额,当他们点击按钮时,余额下降 5000,当他们达到 0 时,他们从 20,000 开始,我想要一个警报出现(我有那个工作)和按钮被禁用 - 我无法让它工作,任何人都可以解释一下吗?所有功能都运行良好,顺便说一句,我只是想在 "Subtract" 功能中添加禁用按钮 - 谢谢!
这是我正在使用的代码
<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");
}
}