gpt4 book ai didi

javascript - "else"在 javascript 函数中不起作用

转载 作者:行者123 更新时间:2023-11-30 07:06:34 24 4
gpt4 key购买 nike

我是 javascript 的新手,但我正在尝试制作一个复选框,将 billto 信息复制到 shipto 框中。我有一个带有 onclick 事件的复选框,设置如下:

<input type="checkbox" name="chkSame" id="chkSame" onClick="fncCheckbox()"/> same as customer info<br/>

不过,我在以下函数的 Else 行收到错误“Expected ';'”。如果我完全取出 IF 语句,它就会起作用。如果我只是摆脱 ELSE 或者如果我将 ELSE 保留为 1 行并摆脱 { } 括号,它就会起作用。当我在测试页上设置非常相似的内容时,它会起作用。我不知道为什么它在这种情况下不起作用。函数如下:

<script type="text/javascript">
function fncCheckbox()
{
if (document.RepairRequestform.chkSame.checked) {
document.RepairRequestform.txtShipName.value = document.RepairRequestform.txtBillName.value;
document.RepairRequestform.txtShipCompany.value = document.RepairRequestform.txtBillCompany.value;
document.RepairRequestform.txtShipAddress.value = document.RepairRequestform.txtBillAddress.value;
document.RepairRequestform.txtShipAddress2.value = document.RepairRequestform.txtBillAddress2.value;
document.RepairRequestform.txtShipCity.value = document.RepairRequestform.txtBillCity.value;
document.RepairRequestform.txtShipState.value = document.RepairRequestform.txtBillState.value;
document.RepairRequestform.txtShipZip.value = document.RepairRequestform.txtBillZip.value;
} Else {
document.RepairRequestform.txtShipName.value = "";
document.RepairRequestform.txtShipCompany.value = "";
document.RepairRequestform.txtShipAddress.value = "";
document.RepairRequestform.txtShipAddress2.value = "";
document.RepairRequestform.txtShipCity.value = "";
document.RepairRequestform.txtShipState.value = "";
document.RepairRequestform.txtShipZip.value = "";
}
}
</script>

最佳答案

else 应该全部小写,JavaScript 区分大小写。

关于javascript - "else"在 javascript 函数中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3322701/

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