簡體   English   中英

當腳本標簽中有 2 個函數時,為什么會出現“函數未定義”錯誤?

[英]Why am I getting a "function not defined" error when there are 2 functions in the script tag?

<head>的腳本標記部分:

  function reload()
  {
     //some code


  }
  function bookconfirm(clickinfo)
  {
        //some code
  }

調用它們的部分:

           <select name="city" onchange="reload()">

          <td><button type="button" onclick="bookconfirm(<?php echo $c;?>)">Book</button></td>

錯誤:

             Uncaught ReferenceError: reload is not defined at HTMLSelectElement.onchange


        Uncaught ReferenceError: bookconfirm is not defined  at HTMLButtonElement.onclick 

我可能無法理解函數在 js 或其他東西中是如何工作的,感謝您的時間和知識。

似乎工作正常。 確保你的 html 是正確的,你的 select 語句需要一些微調。 還要確保在調用腳本之前出現 html。 (即,將腳本放在結束 body 標記之前,盡管在這種情況下,您也可以將其保留在 head 標記中,但請記住,如果 javascript 在 dom 完全加載之前嘗試執行,您可能會收到錯誤消息)

 function reload() { console.log('reload'); } function bookconfirm(clickinfo) { console.log(clickinfo); }
 <select name="city" onchange="reload()"> <option></option> <option>test</option> </select> <button type="button" onclick="bookconfirm('bookconfirm')">Book</button>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM