我遇到了問題,只有部分驗證工作在哪裏,我似乎無法找出問題出在哪裏。在該頁面中,我對地址,城市,郵政編碼和信用卡進行了驗證,但驗證不適用於信用卡。對jQuery的驗證沒有完全正常工作
HTML:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Billing Information</title>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script type="text/javascript" src="test.js"></script>
<style type="text/css">
.error {
background-color: #ffc;
border: 1px solid red;
}
</style>
</head>
<body>
<table border='1'>
<tr>
<td>
<form action="signin.html" id="signup">
<p>
<label for="name">Address:</label>
<input type="text" name="address" id="address" />
</p>
<p>
<label for="name">City: </label>
<input type="text" name="city" id="city" />
</p>
<p>
<label for="name">ZIP Code:</label>
<input type="text" name="zip" id="zip" size='3'/>
</p>
</td>
<td>
<p><b>What is your preferred billing method?</b></p>
<input type="radio" name="payment" id="ccard" value="cc" />
<label for="cCard">Credit Card</label><br />
<div id="cardInfo">
<!-- doesn't work here -->
<label for="name">Card Number: </label>
<input type="text" name="cnum" id="cnum" size='15' /> <br />
<label for="name">Expiration Date:</label>
<input type="text" name="exp" id="exp" size='4' />
</div>
</td>
<td>
<p align='center'>
<input type="submit" id='submit'>
</p>
</td>
</form>
</tr>
</table>
</body>
</html>
JS:
$(function() {
// validations using plugin
$('#signup').validate({
rules: {
address: 'required',
city: 'required',
zip: {
required:true,
digits:true,
minlength:5,
maxlength:5
},
cnum: 'required'
}
});
});
編輯:如果我在移動卡號的第一列中,驗證工作,但是當它在第二列它不
做你嘗試'cardInfo: 'required''不僅僅是'CNUM:' required''? – uday
嘗試過,但它不起作用 – Dan
看到我的答案。另外,我建議你把你的代碼放在www.jsfiddle.net上,以使其他人更容易調試 – uday