gpt4 book ai didi

javascript - 如何修复 XHTML 1.0 Strict 中的表单操作问题

转载 作者:行者123 更新时间:2023-11-30 10:45:48 25 4
gpt4 key购买 nike

我在验证我的代码是否符合 XHTML 1.0 Strict 时遇到了问题。

我一直在使用 w.3 validator尝试验证我的页面。它告诉我

Line 112, Column 24: required attribute "action" not specified

        <form id="orderform">

The attribute given above is required for an element that you've used, but you have omitted it. For instance, in most HTML and XHTML document types the "type" attribute is required on the "script" element and the "alt" attribute is required for the "img" element.

Typical values for type are type="text/css" for and type="text/javascript" for script.

我是 XHMTL 和 CSS 的新手,此时我也在学习 Javascript,我进行了 Google 搜索,发现很多人都在谈论使用 Javascript 行来修复错误,但他们都不够清楚。这里有没有人可以为我提供一个明确的解释?

这是我的 XHTML 代码..

    <form id="orderform">
<div class="field">
Name:
<input type="text" id="name" name="name" value="" />
</div>
<div class="field">
# of Home shirts:
<input type="text" id="homeshirt" name="home" value="" onchange="updateOrder();" />
</div>
<div class="field">
# of Away shirts:
<input type="text" id="awayshirt" name="away" value="" onchange="updateOrder();" />
</div>
<div class="field">
Date of collection:
<input type="text" id="date" name="date" value="" />
</div>
<div class="field">
Subtotal:
<input type="text" id="subtotal" name="subtotal" value="" readonly="readonly" />
</div>
<div class="field">
Tax:
<input type="text" id="tax" name="tax" value="" readonly="readonly" />
</div>
<div class="field">
Total:
<input type="text" id="total" name="total" value="" readonly="readonly" />
</div>
<div id="button">
<input type="button" class="button" value="Place Order" onclick="placeOrder(this.form);" />
</div>
</form>

还有我的 Javascript...

<script type="text/javascript">
function updateOrder() {
const TAXRATE = 0.0925;
const SHIRTPRICE = 39.99;
var numHomeShirt = parseInt(document.getElementById("homeshirt").value);
var numAwayShirt = parseInt(document.getElementById("awayshirt").value);
if (isNaN(numHomeShirt))
numHomeShirt = 0;
if (isNaN(numAwayShirt))
numAwayShirt = 0;
var subTotal = (numHomeShirt + numAwayShirt) * SHIRTPRICE;
var tax = subTotal * TAXRATE;
var total = subTotal + tax;
document.getElementById("subtotal").value = "£" + subTotal.toFixed(2);
document.getElementById("tax").value = "£" + tax.toFixed(2);
document.getElementById("total").value = "£" + total.toFixed(2);
}

function placeOrder(form) {
if (document.getElementById("name").value == "")
alert("I'm sorry but you need to provide a name to print on the shirt.");

else if (document.getElementById("date").value == "")
alert ("I'm sorry but you must provide a date you can collect your shirt(s).");

}
</script>

谢谢你的时间,

干杯。杰米

最佳答案

也许这太明显了,我遗漏了一些东西,但为什么不直接将 action 属性添加到表单中呢?

关于javascript - 如何修复 XHTML 1.0 Strict 中的表单操作问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8416631/

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