嘿傢伙。我目前使用非常低效的腳本來驗證我的表單。代碼非常龐大。Javascript/jQuery表單驗證
這樣做的想法是,如果輸入框爲空,輸入標籤將突出顯示爲紅色,並在窗體的頂部顯示div的錯誤信息。
function new_receiver(){
if (document.getElementById("RecieversName").value ==""){ //First Name
var txt=document.getElementById("error_receiver");
txt.innerHTML="<p><font color=\"#FF0000\">You need to enter a Name!</font></p>";
window.document.getElementById("RecieversName_label").style.color = '#FF0000';
//Reset
window.document.getElementById("receiver_check_label").style.color = '#000000';
window.document.getElementById("RecieversNumber_label").style.color = '#000000';
window.document.getElementById("RecieversEmail_label").style.color = '#000000';
}else if (document.getElementById("RecieversNumber").value ==""){ //First Name
var txt=document.getElementById("error_receiver");
txt.innerHTML="<p><font color=\"#FF0000\">You need to enter a Phone Number!</font></p>";
window.document.getElementById("RecieversNumber_label").style.color = '#FF0000';
//Reset
window.document.getElementById("receiver_check_label").style.color = '#000000';
window.document.getElementById("RecieversName_label").style.color = '#000000';
window.document.getElementById("RecieversEmail_label").style.color = '#000000'
}else if (document.getElementById("RecieversNumber").value ==""){ //First Name
var txt=document.getElementById("error_receiver");
txt.innerHTML="<p><font color=\"#FF0000\">You need to enter an Email!</font></p>";
window.document.getElementById("RecieversEmail_label").style.color = '#FF0000';
//Reset
window.document.getElementById("receiver_check_label").style.color = '#000000';
window.document.getElementById("RecieversName_label").style.color = '#000000';
window.document.getElementById("RecieversNumber_label").style.color = '#000000';
}else{
from.receiver.submit();
}」
任何意見或方法來使這個過程容易,因爲我的一些形式最多有9個輸入框和這種驗證方法是巨大的!
乾杯人!
塞繆爾。
輝煌。隊友的歡呼聲! – 2011-04-19 09:46:52