當我輸入超過 8 個字符且字符不全是數(shù)字時,此表單應顯示錯誤消息。為什么不起作用? <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> </head> <body> <form name="myform" onsubmit="return validateForm()"> <input type="text" id="username"> <input type="submit"> </form> <script> function validateForm(){ var x = document.getElementById("username"); if(x.match(/^[0-9]{8,}$/)) return true; else{ alert("MESSAGE"); return false; } } </script> </body> </html>
為什么當我輸入錯誤的單詞時不顯示警告消息?
慕村225694
2021-06-29 08:05:29