gpt4 book ai didi

Javascript:检测复选框是否选中不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:37:43 24 4
gpt4 key购买 nike

我已经仔细阅读了所有教程,并且一直在竭尽全力试图让它发挥作用。

onClick 正确触发,但它永远不会进入 IF 循环,在该循环中检查复选框是否已被选中。

<!DOCTYPE html>
<html>
<head>
</head>

<header>
<script>

function updateTotal() {
document.orderform.total.value = 1*document.orderform.subtotal.value + 1*document.orderform.tax.value + 1*document.orderform.shipping.value;
}

**function applyDiscount(x) {


if (document.orderform.getElementById(x).checked == true) {
alert("Made it in if");
document.orderform.subtotal.value = .7*document.orderform.subtotal.value;
updateTotal();
}**

}

</script>
</header>

<body>


<section>
<h1>H1 here</h1>

<article>
<p>Article text here</p>
</article>

<form name="orderform" id="orderform" method="post" action="result.php">

<label for="firstname">First Name</label>
<input type="text" name="firstname" id="firstname" placeholder="Enter First Name Here" />
<br />


<label for="subtotal">Subtotal</label>
<input type="text" name="subtotal" id="subtotal" value="10" onChange="updateTotal()"/>
<br />

<label for="shipping">Shipping</label>
<input type="text" name="shipping" id="shipping" value="2" onChange="updateTotal()"/>
<br />

<label for="tax">Tax</label>
<input type="text" name="tax" id="tax" value="1" onChange="updateTotal()" />
<br />

<label for="total">Total</label>
<input type="text" name="total" id="total" value="13" />
<br />

<label for="discountbox">Apply 30% discount</label>
<input type="checkbox" name="discountbox" id="discountbox" onClick="applyDiscount(this.id)"/>

<input type="submit" name="submit" />

</form>

</section>

<footer>
<p>Footer here</p>
</footer>


</body>

最佳答案

你能不能把这个条件说一下

if (document.getElementById('discountbox').checked == true)

关于Javascript:检测复选框是否选中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5561570/

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