简体   繁体   English

未捕获到的ReferenceError:在HTMLInputElement.onclick上未定义myFunctionName

[英]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.

相关问题 未捕获的参考错误:<function> 未在 HTMLInputElement.onclick 中定义 - Uncaught ReferenceError: <function> is not defined at HTMLInputElement.onclick 未捕获的ReferenceError:在HTMLInputElement.onclick中未定义函数 - Uncaught ReferenceError: function is not defined at HTMLInputElement.onclick 未捕获的ReferenceError:在HTMLInputElement.onclick中未定义functionXXX - Uncaught ReferenceError: functionXXX is not defined at HTMLInputElement.onclick 未被捕获的ReferenceError:未在HTMLInputElement.onclick上定义SearchAddress - Uncaught ReferenceError: SearchAddress is not defined at HTMLInputElement.onclick 未捕获的 ReferenceError:在 HTMLInputElement.onclick 中未定义排序 - Uncaught ReferenceError: sort is not defined at HTMLInputElement.onclick 未捕获的ReferenceError:函数可用时未在HTMLInputElement.onclick上定义函数 - Uncaught ReferenceError: function is not defined at HTMLInputElement.onclick while function is available ReferenceError: submitForm 未在 HTMLInputElement.onclick 中定义 - ReferenceError: submitForm is not defined at HTMLInputElement.onclick ReferenceError:显示未在 HTMLInputElement.onclick 中定义 - ReferenceError: display is not defined at HTMLInputElement.onclick 未在 HTMLInputElement.onclick 中定义 - is not defined at HTMLInputElement.onclick 未捕获的 ReferenceError:AddAnime 未在 HTMLInputElement.onclick 中定义(AnimeSite.html:51) - Uncaught ReferenceError: AddAnime is not defined at HTMLInputElement.onclick (AnimeSite.html:51)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM