我目前正在为我在空闲时间工作的网站制作捐赠页面。一直很顺利,直到上周遇到了问题。我的 JS 没有正确响应我的 HTML,我无法修复它。这是我的 HTML:
var donateAmount = document.getElementById("selectedAmount");
if (donateAmount.value == "amount0") {
var totalAmount = 0;
} else if (donateAmount.value == "amount1") {
var totalAmount = 10;
} else if (donateAmount.value == "amount2") {
var totalAmount = 50;
} else if (donateAmount.value == "amount3") {
var totalAmount = 100;
} else if (donateAmount.value == "amount4") {
var totalAmount = 500;
};
function donateIsPressed() {
if (totalAmount >= = 0) {
alert("Thank you for your donation of " + totalAmount "$!")
} else {
alert("You didn't select anything!")
};
};
<form id="selectedAmount" name="selectedAmount">
<input type="radio" name="donateRadio" value="amount0"> 0 Dollars </input> <br>
<input type="radio" name="donateRadio" value="amount1"> 10 Dollars </input> <br>
<input type="radio" name="donateRadio" value="amount2"> 50 Dollars </input> <br>
<input type="radio" name="donateRadio" value="amount3"> 100 Dollars </input> <br>
<input type="radio" name="donateRadio" value="amount4"> 500 Dollars </input>
</form>
<div onclick='donateIsPressed ();' class="donateButton" id="processDonation"> test donate button </div>
HTML 非常简单,有一个带有多个选项的标签,以及一个应该开始交易的按钮。JS 应该做的是检查选择了哪个选项,然后将“totalAmount”变量设置为所选的任何值。然后它应该根据 totalAmount 的值给出答案。但是,它们都不起作用,而且我目前无法修复。所以如果你们中的一个人能指出我正确的方向,我将不胜感激
摇曳的蔷薇
料青山看我应如是
达令说
阿晨1998
相关分类