我是初學者,我需要一些幫助來完成我的任務。我無法弄清楚我做錯了什麼。標籤和提交按鈕顯示在html中,但是當我點擊提交按鈕時,它不會驗證表單。我的HTML表單驗證不起作用
我的任務是製作一個表格來輸入你的名字。 Ons提交函數來驗證名稱被調用,將驗證名稱不能爲空,並且必須超過6個字符。
<html>
<head>
<body>
<form name="myForm" autocomplete="on" onsubmit="return validateForm()">
<p><label>First name (required) <input type="text" id="firstName"
autofocus="autofocus" /> </label></p>
</form>
<input type="submit" name="S1" value="Submit response" />
<script>
function validateForm(){
var firstName=document.getElementById("firstName");
if (firstName.value.length<6){
alert("Please enter your first name (6 characters or more)");
firstName.focus();
return false;
}
alert("Thank you for your submission");
return true;
}
</script>
</body>
</head>
</html>
你的HTML被打破:你的第一個輸入字段是你''
'但是當我點擊提交按鈕時,它不會驗證表格'' 他似乎確實解釋了他的困難,@HoboSapiens。 – SZenC 2014-11-25 07:53:50
@HoboSapiens有沒有[錯誤](http://www.w3.org/TR/html401/interact/forms.html#edef-LABEL)在標籤內輸入一個輸入 – MLeFevre 2014-11-25 08:13:31