HTMLページに、送信ボタンをクリックすると消去されるフォームがあります。ユーザーがエラーを修正する必要がある場合に備えて、submitをクリックした後にデータをフォームに残す方法を知りたかったのです。どんな助けもありがとう!ここで投稿をクリックした後に入力したデータをhtml形式で保持する方法
はhtmlコードです:
<form id = "contactform" action = "">
<label> Name:
<input name = "firstname" type = "text" id = "firstname" maxlength = "50"/>
</label>
<label> Last Name:
<input name = "lastname" type = "text" id = "lastname" maxlength = "150" />
</label>
<label> Address:
<input name = "address" type = "text" id = "address" maxlength = "200"/>
</label>
<label> Postcode:
<input name = "postcode" type = "text" id = "postcode" maxlength = "50" />
</label>
<input type = "submit" value = "Submit" onclick = "validate()" />
<input type = "reset" value = "Clear" />
</p>
</form>
、ここではjavascriptのコードです:
function validate() {
var firstname = document.getElementById('firstname');
var lastname = document.getElementById('lastname');
var address = document.getElementById('address');
var postcode = document.getElementById('postcode');
if(firstname.value == "") {
alert("Make sure the first name field is filled");
return false;
}
if(lastname.value == "") {
alert("Make sure the last name field is filled");
return false;
}
if(address.value == "") {
alert("Make sure the address field is filled");
return false;
}
if(postcode.value == "") {
alert("Make sure the post code field is filled");
return false;
}
なぜ送信をクリックしたユーザーは何かを編集したいのですか? – VivekN
^^誰も完璧ではなく、おそらく姓を入力するのを忘れてしまったからです。彼の名前をもう一度記入したくないのですか? .. – Zak
ページがリフレッシュされるときにフォームが消去され、ajaxを使用できるため、ページがリフレッシュされず、送信後に入力フィールドにサーバーの終了データがバインドされます。 – lilixiaocc