<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>注册页面</title> </head> <body> <h1>会员注册</h1> <form action="/register" method="get"> <table> <tr> <td>用户名:</td> <td> <input type="text" style="width: 300px" name="username" pattern="/^[$_A-Za-z][A-Za-z0-9]{5,15}$" placeholder="只能以$_或者字母开头的6-16位字母或者数字组合"> </td> </tr> <tr> <td>密码:</td> <td> <input type="password" style="width: 270px" name="password" pattern="/^[A_Z][A-Za-z0-9]{5,15}$" placeholder="必须以大写字母开头6-16位字母或者数字组合"> </td> </tr> <tr> <td>确认密码:</td> <td> <input type="password" name="rePassword" placeholder="请与上述密码保持输入一致"> </td> </tr> <tr> <td>姓名:</td> <td> <input type="text" name="name"> </td> </tr> <tr> <td>年龄:</td> <td> <input type="number" name="age" min="16" max="140"> </td> </tr> <tr> <td>性别:</td> <td> <input type="radio" name="sex" checked/>男 <input type="radio" name="sex">女 </td> </tr> <tr> <td>身份证号:</td> <td> <input type="text" name="idCard" pattern="/^[1-9]\d{5}(19|20|21)\d{2}((0[1- 9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9 Xx]$/"> </td> </tr> <tr> <td>出生年月:</td> <td> <input type="date" name="birthday"> </td> </tr> <tr> <td>居住地址:</td> <td> 省份:<select id="province" name="province" οnchange="changeProvince(this.selectedIndex)"></select> 城市:<select id="city" name="city"></select> <input type="text" style="width: 60px" name="address" placeholder="详细地址"> </td> </tr> <tr> <td>上传文件:</td> <td> <input type="file" name="file"> </td> </tr> <tr> <td>个人简介:</td> <td> <textarea name="description" cols="30" rows="10"></textarea> </td> </tr> <tr> <td></td> <td> <input type="submit" value="注册"> <input type="reset" value="重置"> </td> </tr> </table> </form> </body> </html> <script type="text/javascript"> var provinces=["请选择省份","北京市","天津市","上海市","重庆市","江苏省","浙江省","江西省","海南省"]; var citys=[ ["请选择城市"], ["北京市"], ["天津市"], ["上海市"], ["重庆市"], ["南京市","无锡市","徐州市","常州市","苏州市","南通市","连云港市","淮安市","盐城市","扬州市","镇江市","泰州市","宿迁市"], ["杭州市","宁波市","温州市","绍兴市","湖州市","嘉兴市","金华市","衢州市","台州市","丽水市","舟山"], ["南昌市","九江市","上饶市","抚州市","宜春市","吉安市","赣州市","景德镇","萍乡市","新余市","鹰潭市"], ["海口市","三亚市","三沙市","儋州市"] ]; window.οnlοad=function(){ var province=document.getElementById("province"); var city=document.getElementById("city"); var index=0; //创建好后加入到列表中 for(var i in provinces) { var option = document.createElement("option"); option.text=province
s[i]; option.value=provinces[i]; province.appendChild(option); } var option = document.createElement("option"); option.text=citys[index]; option.value=citys[index]; city.appendChild(option); } function changeProvince(selectedIndex){ var city=document.getElementById("city"); city.options.length=0; for(var i in citys[selectedIndex]) { var option = document.createElement("option"); option.text=citys[selectedIndex][i]; option.value=citys[selectedIndex][i]; city.appendChild(option); } } </script>
效果图
省份城市采用js技术,可以选择省份和城市。
用户名密码以及身份证采用正则做验证。