我正在处理 java 脚本,我被困在一个阶段。在我的项目中,我必须在提交表单时验证所有字段,并在表单字段上方的订单列表中的同一页面上显示错误消息。下面是我的代码
function validation(){
var errorMsg=new Array();
//var errorMsg = "";
if(document.getElementById("fullname").value = " "){
errorMsg[0] = "Please Enter Full Name\n"
}
if(document.getElementById("street").value = " "){
errorMsg[1]= "Please Enter Street Name\n"
}
if(document.getElementById("postcode").value = " "){
errorMsg[2]= "Please Enter Postlecode\n"
}
if(document.getElementById("phone").value = " "){
errorMsg[3]= "Please Enter Phone Number\n"
}
if(document.getElementById("email").value = " "){
errorMsg[4]= "Please Enter Email Id\n"
}
if(errorMsg!=" "){
var r =" ";
for(var i=0;i<=errorMsg.length-1;i++){
document.getElementById("error").innerHTML="<li>"+errorMsg[i]+"</li>"
}
return false;
}
}
</script>
当我运行这段代码时,它只给了我最后一个值
谁能帮助我如何在表单顶部显示错误消息?