【发布时间】:2011-03-20 08:36:23
【问题描述】:
我对 javascript 很陌生,但我正在尝试制作一个复选框,将 billto 信息复制到 shipto 框中。我有一个带有 onclick 事件的复选框,设置如下:
<input type="checkbox" name="chkSame" id="chkSame" onClick="fncCheckbox()"/> same as customer info<br/>
但是,我在以下函数的 Else 行中收到“预期的 ';'”错误。如果我完全取出 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>
【问题讨论】:
标签: javascript events checkbox onclick if-statement