jQuery練習---表單驗證之單選按鈕驗證


<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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM