JavaScript ?? ??? ??
JavaScript ?? ??? ??
JavaScript ?? ??? ??
JavaScript? ???? ??? ???? ?? HTML ???? ??? ?? ???? ???? ???? ? ??? ? ????.
?? ???? ???? ????? ?? JavaScript? ?????.
?? ???? ?? ??? ?????????
??? ??? ??? ???? ?????????
??? ??? ?????? ???????
?? ?? ??? ???? ???????
??(?? ??) ??
?? ??? ???? ??? ??(?? ??) ??? ????? ???? ? ?????. ?? ?? ?? ?? ??? ?? ??? ?? ??? ???? ??? ?? ?? false???. ??? ??? ??? ?? ?? true???(???? ??? ??? ??):
?? verifyForm()
{
var x =document.forms["myForm"]["fname"].value;
if (x==null || x=="")
{
Alert("?? ??? ??? ???. filled in");
return false;
}
}
? ??? ??? ??? ? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <head> <script> function validateForm(){ var x=document.forms["myForm"]["fname"].value; if (x==null || x==""){ alert("姓必須填寫"); return false; } } </script> </head> <body> <form name="myForm" action="demo-form.php" onsubmit="return validateForm()" method="post"> 姓: <input type="text" name="fname"> <input type="submit" value="提交"> </form> </body> </html>
??? ??
?? ??? ??? ???? ??? ????? ?????. ??? ??? ?? ??.
?? ?? ???? @ ??? ???(.)? ????? ?? ?????. ??? @? ??? ??? ? ?? ??? ? ? ??? @ ?? ???? ?? ?? ??? ???.
function verifyForm(){
var x=document.forms["myForm"]["email" ].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>= x.length){
Alert("??? ??? ??? ????");
return false;
}
}
??? HTML ??? ?? ?? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <head> <script> function validateForm(){ var x=document.forms["myForm"]["email"].value; var atpos=x.indexOf("@"); var dotpos=x.lastIndexOf("."); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length){ alert("不是一個(gè)有效的 e-mail 地址"); return false; } } </script> </head> <body> <form name="myForm" action="demo-form.php" onsubmit="return validateForm();" method="post"> Email: <input type="text" name="email"> <input type="submit" value="提交"> </form> </body> </html>