- 分享
- 0
- 人气
- 0
- 主题
- 45
- 帖子
- 854
- UID
- 227081
- 积分
- 1166
- 阅读权限
- 18
- 注册时间
- 2009-5-14
- 最后登录
- 2017-2-7
- 在线时间
- 5417 小时
|
本帖最后由 meijie85 于 2011-6-18 03:54 PM 编辑
回复 18# leon_lcl
这先不谈,我现在这个function都不懂哪里有错,gender没反应。能办忙看下吗?
<!DOCTYPE>
<html>
<head>
<title>Meei Kiat.com</title>
</head>
<script type='text/javascript'>
function formValidator(){
var name=document.getElementById('name');
var age=document.getElementById('age');
var gender=document.getElementById('gender');
var email=document.getElementById('email');
if(isAlphabet(name, "Please enter your name!")){
if(isNumeric(age, "Please enter your age!")){
if(madeSelection(gender, "Please select your gender!")){
if(emailValidator(email, "Please enter your email!")){
return true;
}
}
}
}
return false;
}
function notEmpty(elem, helperMsg){
if(elem.value.length == 0){
alert(helperMsg);
elem.focus();
return false;
}
return true;
}
function isNumeric(elem, helperMsg){
var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression)){
return true;
}
else
{
alert(helperMsg);
elem.focus();
return false;
}
}
function isAlphabet(elem, helperMsg){
var alphaExp = /^[a-zA-Z]+$/;
if(elem.value.match(alphaExp)){
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}
function madeSelection(elem, helperMsg){
if(elem.value == "Please Choose"){
alert(helperMsg);
elem.focus();
return false;
}
else
{
return true;
}
}
function emailValidator(elem,helperMsg){
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
if(elem.value.match(emailExp)){
return true;
}
else
{
alert(helperMsg);
elem.focus();
return false;
}
}
</script>
<form onsubmit='return formValidator()'>
Name: <input type='text' id='name'/><br/>
Age: <input type='text' id='age'/><br/>
Gender: <select id='gender'>
<option>Please Choose</option>
<option>Male</option>
<option>Female</option>
</select><br/>
Email: <input type='text' id='email'/><br/>
<input type='submit' value='Submit'/>
</form>
</html> |
|