我试图创建一个验证错误消息,该消息位于HTML窗体之上。此验证错误消息应出现在“分区”具有ID = POP_UP如何在窗体顶部显示错误消息
<form method="post" enctype="text/plain" name="review" onsubmit="return validate_ip()">
<input type="text" name="uname" id="uname" placeholder="Enter your name"><br>
<input type="Email" name="mail" id="mail" placeholder="Enter email id"><br>
<div id="pop_up"></div>
<textarea name="text" id="myself" placeholder="Say something about yourself"></textarea><br>
<br>
<input type="submit" name="submit" value="send">
应该使用javascript显示该错误消息。函数alert_box()应该设置错误消息的样式并显示错误消息。
var val=/[\w~!#$%^&*]+[\W]+[\w~!#$%^&*][email protected]+[\w~!#$%^&*]+.+[\w]/;
function validate_ip(){
var name=document.getElementById("uname").value;
console.log(name);
var mail=document.getElementById("mail").value;
var testyy=val.test(mail);
var myself=document.getElementById("myself").value;
if (name.length<3){
alert_box("Enter your name");
document.getElementById('uname').focus();
return false;
}
else if (!testyy){
alert_box("Reenter Email id");
document.getElementById("mail").focus();
return false;
}
else if(myself.length<60)
{
alert_box("Atleast say 30 letters about yourself");
document.getElementById("myself").focus();
return false;
}
else
return true;
}
function alert_box(a){
var x= document.getElementById("pop_up");
x.style.height="200px";
x.style.width="200px";
x.style.background="red";
x.innerHTML=a;
}
我无法在窗体顶部获取eroor消息框。 编辑:在上面,我的意思是错误框应显示在前台,而窗体在后台。
的jsfiddle:https://jsfiddle.net/anoopj/eykq9d1p/
你有没有把股利的形式上面? – InvincibleM
您在控制台中遇到什么错误? – baao
您需要使用CSS定位才能使框相互重叠。 https://stackoverflow.com/questions/44831670/how-to-make-error-message-appear-on-top-of-form –