<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>表单验证之单选按钮验证</title>
<style type="text/css">
.infobox {
margin-top: 10px;
}
.error {
color: red;
}
</style>
<script src="../jquery-1.5.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$(‘.error‘).hide();
$(‘.submit‘).click(function(event) {
var count = $(‘input:checked‘).length;
if(count==0) {
$(‘.error‘).show();
$(‘.result‘).hide();
}
else {
$(‘.error‘).hide();
$(‘.result‘).show();
$(‘.result‘).text(‘你选择了 ‘ + $(‘input:checked‘).attr(‘value‘));
}
event.preventDefault();
});
});
</script>
<body>
<form>
<input type="radio" name="paymode" value="信用卡支付" class="infobox">
信用卡
<br />
<input type="radio" name="paymode" value="礼品卡支付" class="infobox">
礼品卡
<br />
<input type="radio" name="paymode" value="消费券支付" class="infobox">
消费券
<br />
<p class="error">
请选择支付方式!
</p>
<p class="result">
</p>
<input class="submit" type="submit" name="submit" value="提交">
</form>
</body>
</html>