【问题标题】:"else" doesn't work in javascript function“else”在 javascript 函数中不起作用
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-21
      • 1970-01-01
      • 2011-08-31
      • 2013-09-27
      • 2014-07-02
      • 1970-01-01
      相关资源
      最近更新 更多