[英]Radio validation with Javascript not working
我有一些 HTML 和 Javascript 代碼。 每當我測試它時,我都會收到一個錯誤,指出我的函數沒有定義。 我不知道為什么會這樣。 我已經檢查了代碼,我沒有看到任何似乎有問題的地方。
function proccessSecurity(el) { if (el.value == "none") { document.getElementById('tid-password').style = "display: none;"; document.getElementById('tid-users-allowed').style = "display: none;"; } if (el.value == "password") { document.getElementById('tid-password').style = "display: block;"; document.getElementById('tid-users-allowed').style = "display: none;"; } if (el.value == "specific") { document.getElementById('tid-password').style = "display: none;"; document.getElementById('tid-users-allowed').style = "display: block;"; } }
<textarea rows="20" cols="100" id="tid-text-area"></textarea><br><br> Security<br> <input onchange="processSecurity(this);" type="radio" name="security" value="none" checked> No security.</input><br> <input onchange="processSecurity(this);" type="radio" name="security" value="password"> Allow only users with a password.</input><br> <input onchange="processSecurity(this);" type="radio" name="security" value="specific"> Allow only specified users.</input><br> <input style="display: none;" type="password" id="tid-password"><br><br> <input style="display: none;" type="text" id="tid-users-allowed"><br><br>
您的內聯處理程序是processSecurity
,但您的函數被定義為proccessSecurity
。 簡單的錯別字。
您應該更改代碼中的錯字
過程安全
到
流程安全
它不會顯示未定義的函數
function proccessSecurity(el) { if (el.value == "none") { document.getElementById('tid-password').style = "display: none;"; document.getElementById('tid-users-allowed').style = "display: none;"; } if (el.value == "password") { document.getElementById('tid-password').style = "display: block;"; document.getElementById('tid-users-allowed').style = "display: none;"; } if (el.value == "specific") { document.getElementById('tid-password').style = "display: none;"; document.getElementById('tid-users-allowed').style = "display: block;"; } }
<textarea rows="20" cols="100" id="tid-text-area"></textarea><br><br> Security<br> <input onchange="proccessSecurity(this);" type="radio" name="security" value="none" checked> No security.</input><br> <input onchange="proccessSecurity(this);" type="radio" name="security" value="password"> Allow only users with a password.</input><br> <input onchange="proccessSecurity(this);" type="radio" name="security" value="specific"> Allow only specified users.</input><br> <input style="display: none;" type="password" id="tid-password"><br><br> <input style="display: none;" type="text" id="tid-users-allowed"><br><br>
<input onchange="processSecurity(this);"
=> <input onchange="proccessSecurity(this);"
你錯過了過程的“c”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.