JS验证邮箱手机还有姓名的必填功能,怎么做 急急急

JavaScript029

JS验证邮箱手机还有姓名的必填功能,怎么做 急急急,第1张

提交的时候给表调加一个 onsubmit事件,判断所写的js方法是否成功

<html>

<form method="post" action="" onsubmit="sub()">

<table>

<tr>

<td>

姓名:

</td>

<td>

<input type="text" name="name" id="name">

</td>

</tr>

<tr>

<td>

年龄:

</td>

<td>

<input type="text" name="age" id="age">

</td>

</tr>

<tr align="center">

<td>

<input type="submit" value="提交">

</td>

<td>

<input type="reset">

</td>

</tr>

</form>

</html>

<script>

//验证姓名

function checkname(){

.....

}

//验证年龄

function checkage(){

.....

}

//验证是否能提交

function sub(){

if(checkname()==false){

return false

}else if(checkage()==false){

return false

}

return true

}

</script>

临时按照你的要求写了一个,有什么问题可以再补充。

<!DOCTYPE HTML>

<html>

<body>

<form method="get">

用户名:<input type="text" name="user_name" required placeholder="请填写用户名"><br/>

<form name="form1">

密码:<input id=password1 class=textbox type=password name=pwd1 required placeholder="请填写密码"/><br/>

重复密码:<input id=password2 class=textbox type=password name=password2 required placeholder="请重复密码"/><br/>

手机号码: <input type="number" name="points" min="10000000000" max="19999999999" required placeholder="请填写手机号码"/><br/>

E-mail: <input type="email" name="user_email" required placeholder="请填写E-mail"/><br />

<input type="submit" />

</form>

</body>

</html>