課程
/前端開發(fā)
/jQuery
/jQuery插件——Validation Plugin
怎么把錯誤信息返回至頁面中呢,這個好像沒講清楚啊
2015-11-01
源自:jQuery插件——Validation Plugin 1-2
正在回答
這個代碼哪里錯了???
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
<link href="type.css" rel="stylesheet" type="text/css">
<script ?src="vendor/jquery.validate-1.13.1.js" type="text/javascript"></script>
<script src="vendor/jquery-1.10.0.js" type="text/javascript"></script>
</head>
<body>
<form id="demoForm" method='post'>
<fieldset>
<legend>用戶登錄</legend>
<p>
<label for="username">用戶名</label>
<input type="text" id="username" name="username">
</p>
<label for="password">密碼</label>
<input type="password" id="password" name="password">
<input type="submit" value="登錄">
</fieldset>
</form>
<script type="text/javascript">
$(document).ready(function(){
$("#demoForm").validate({
rules: {
username:{
required:true,
minlength:2,
maxlength:10
},
password:{
maxlength:16
}
messages: {
required:"用戶名必須填寫",
minlength:"用戶名最少為2字符",
maxlength:"用戶名最大為10字符"
required:"密碼必須填寫",
minlength:"密碼最少為2字符",
maxlength:"密碼最大為16字符"
});
</script>
</body>
</html>
css樣式
body {
? ? font-size: 36px;
? ? line-height: 1.6;
p {
? ? margin: 10px 0;
label {
? ? display: inline-block;
? ? min-width: 140px;
label.error {
? ? margin-left: 10px;
? ? color: red;
input, button {
? ? line-height: 35px;
? ? border: 1px solid #999;
? ? min-width: 180px;
input.error {
? ? border: 1px solid red;
input[type=submit], button {
? ? margin-top: 20px;
? ? padding: 10px 0;
/* CSS Document */
舉報
validation讓客戶端表單驗證變?nèi)菀?,縮短用戶等待時間
1 回答rules方法怎樣增加錯誤提示信息
1 回答$.validator.addClassRules方法的錯誤提示信息有什么地方寫?
3 回答請問jQuery validate怎樣將錯誤提示信息顯示在指定的容器中呢?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學習伙伴
掃描二維碼關注慕課網(wǎng)微信公眾號
2015-11-07
這個代碼哪里錯了???
2015-11-07
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
<link href="type.css" rel="stylesheet" type="text/css">
<script ?src="vendor/jquery.validate-1.13.1.js" type="text/javascript"></script>
<script src="vendor/jquery-1.10.0.js" type="text/javascript"></script>
</head>
<body>
<form id="demoForm" method='post'>
<fieldset>
<legend>用戶登錄</legend>
<p>
<label for="username">用戶名</label>
<input type="text" id="username" name="username">
</p>
<p>
<label for="password">密碼</label>
<input type="password" id="password" name="password">
</p>
<p>
<input type="submit" value="登錄">
</p>
</fieldset>
</form>
<script type="text/javascript">
$(document).ready(function(){
$("#demoForm").validate({
rules: {
username:{
required:true,
minlength:2,
maxlength:10
},
password:{
required:true,
minlength:2,
maxlength:16
}
}
messages: {
username:{
required:"用戶名必須填寫",
minlength:"用戶名最少為2字符",
maxlength:"用戶名最大為10字符"
},
password:{
required:"密碼必須填寫",
minlength:"密碼最少為2字符",
maxlength:"密碼最大為16字符"
}
}
});
});
</script>
</body>
</html>
body {
? ? font-size: 36px;
? ? line-height: 1.6;
}
p {
? ? margin: 10px 0;
}
label {
? ? display: inline-block;
? ? min-width: 140px;
}
label.error {
? ? margin-left: 10px;
? ? color: red;
}
input, button {
? ? font-size: 36px;
? ? line-height: 35px;
? ? border: 1px solid #999;
? ? min-width: 180px;
}
input.error {
? ? border: 1px solid red;
}
input[type=submit], button {
? ? margin-top: 20px;
? ? font-size: 36px;
? ? padding: 10px 0;
}
/* CSS Document */