[英]JavaScript, why am I getting the error “array is not defined in the function add”
[英]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.