[英]Uncaught ReferenceError: myFunctionName is not defined at HTMLInputElement.onclick
I am using a form with 4 fieldsets. 我正在使用带有4个字段集的表单。 The second and third fieldsets are displayed based on a question I ask with a checkbox.
根据我问的一个复选框显示第二和第三字段集。 I always display the second fieldset and hide the third.
我总是显示第二个字段集,而隐藏第三个字段集。 If you check the box, it should hide the second and show the third fieldset.
如果选中此框,则它应隐藏第二个并显示第三个字段集。
I am using a function in javascript. 我正在使用JavaScript中的函数。 This is the code:
这是代码:
window.onload = function showVlees() {
if (document.getElementById('Vlees').checked) {
document.getElementById('Vleesgerecht').style.display = 'block';
} else {
document.getElementById('Vleesgerecht').style.display = 'none';
}
}
Every time when I click the checkbox I get this error: 每次单击复选框时,都会出现此错误:
Uncaught ReferenceError: showVlees is not defined
at HTMLInputElement.onclick
My checkbox is coded like this: 我的复选框的编码如下:
<td> <input type="checkbox" id="Vlees" name="Vlees" value="Vlees" onclick="showVlees()"> Klik hier als u een vleesgerecht wilt.</input>
Does anyone know what the problem is? 有人知道问题出在哪里吗?
Named function expressions create a variable with a matching name only in their own scope , not the scope of the function they are defined in. 命名函数表达式仅在它们自己的作用域内而不是在定义它们的函数的作用域内创建具有匹配名称的变量。
Use a function declaration and assign it to your load event handler in two steps. 使用函数声明,并通过两个步骤将其分配给您的加载事件处理程序。
function showVlees() {
// etc
}
window.onload = showVlees;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.