1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
| <!DOCTYPE html> <html> <head> <title>信息填写</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src="../jquery.min.js"></script> <script src="../bootstrap/js/bootstrap.min.js"></script> <script src="jquery.validate.js"></script>
<style type="text/css"> body { padding-top: 50px; }
.input-group { margin-bottom: 10px; }
.button-row { margin-top: 10px; }
.alert { margin-top: 10px; } </style>
</head>
<body> <div class="container"> <div class="row"> <div class="col-md-8 col-md-offset-2"> <form id="participant"> <div class="input-group"> <span class="input-group-addon">姓名</span> <input name="name" type="text" class="form-control"> </div> <div class="input-group"> <input type="radio" name="gender" value="true" checked> <span>男</span> <input type="radio" name="gender" value="false"> <span>女</span> </div> <div class="input-group"> <span class="input-group-addon">电话</span> <input name="telephone" type="text" class="form-control" placeholder="如: 0591-6487256, 15005059587"> </div>
<div class="input-group"> <span class="input-group-addon">邮件</span> <input name="mail" type="text" class="form-control" placeholder="如: xxxx@edu-edu.com.cn"> </div>
<div class="button-row"> <button id="submit-participant" class="btn btn-default btn-block">提交</button> </div>
<div id="error-info" class="alert alert-danger fade in" style="display: none;"> <button type="button" class="close" onclick="$('.alert').slideUp()"> <span aria-hidden="true">×</span> </button> <div class="errors"></div> </div> </form> </div> </div> </div> </body>
<script type="text/javascript"> var RegExs = { MAIL: /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/, TELEPHONE: /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$|(^(13|15|18)\d{9}$)/ };
$(document).ready(function() { $.validator.addMethod('notBlank', function(value, element) { return $.trim(value); });
$.validator.addMethod('telephone', function(value, element) { return RegExs.TELEPHONE.test(value); });
$('#participant').validate({ rules: { name: { required: true, notBlank: true }, mail: { required: true, email: true }, telephone: { required: true, telephone: true, } },
messages: { name: { required: '姓名不能为空', notBlank: '姓名不能为空格' }, mail: { required: '邮件不能为空', email: '请输入合格的邮件地址' }, telephone: { required: '电话号码不能为空', telephone: '请输入合格的电话号码', remote: '电话号码已经使用过' } },
errorLabelContainer: $('#error-info div.errors'), wrapper: 'li', showErrors: function(errorMap, errorList) { if (this.numberOfInvalids() > 0) { $('#error-info').show(); } else { $('#error-info').hide(); }
this.defaultShowErrors(); }, submitHandler: function(form) { } }); });
</script> </html>
|