简体   繁体   English

当脚本标签中有 2 个函数时,为什么会出现“函数未定义”错误?

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

The script tag part in <head> : <head>的脚本标记部分:

  function reload()
  {
     //some code


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

The part that are calling them:调用它们的部分:

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

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

Errors:错误:

             Uncaught ReferenceError: reload is not defined at HTMLSelectElement.onchange


        Uncaught ReferenceError: bookconfirm is not defined  at HTMLButtonElement.onclick 

I'm probably unable to understand how functions work in js or something , thanks for your time and knowledge.我可能无法理解函数在 js 或其他东西中是如何工作的,感谢您的时间和知识。

seems to work fine.似乎工作正常。 Make sure your html is correct, your select statement needs some fine tuning.确保你的 html 是正确的,你的 select 语句需要一些微调。 also make sure the html appears before the script is called.还要确保在调用脚本之前出现 html。 (ie place the script just before the closing body tag, although in this case you can also keep it in the head tag but remember you can get errors if the javascript tries to execute before the the dom is fully loaded) (即,将脚本放在结束 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.

相关问题 JavaScript,为什么会出现错误“函数add中未定义数组” - JavaScript, why am I getting the error “array is not defined in the function add” 为什么我收到错误 clearImmediate is not defined? - Why am I getting the error clearImmediate is not defined? 为什么我收到“未定义块”错误? - Why am I getting this error “block is not defined”? 为什么我收到错误“&#39;request&#39; is not defined”? - Why am I getting the error "'request' is not defined"? 为什么我收到此“文档未定义”错误? - Why Am I getting this “document is not defined” error? 为什么这些函数会出现 NaN 错误 - Why am I getting an NaN error with these functions 当我确定函数已定义时,为什么在错误控制台上看到“函数未定义”? - Why am I seeing 'function not defined' on my error console when I'm sure my function IS defined? 为什么我从vue.js组件脚本中的简单for循环中收到“我未定义”错误? - why am i getting 'i is not defined' error from a simple for loop in vue.js component script? 当我需要顶部的函数时,为什么我的脚本中的某些点没有定义函数? - Why is a function not defined at certain points in my script when I am requiring the function at the top? 为什么在脚本标记内的函数中未声明变量时,不会给出错误“未定义变量” - Why a variable when not declared in a function inside script tag doesn't give error “variable not defined”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM