如何巧妙的编写评星功能

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0" />
		<title>默认的五星评分</title>
		<script src="Resource/js/jquery.min.js"></script>
		<script src="Resource/js/jquery.raty.js"></script>
		<style type="text/css">
			p{border:2px dashed blue; padding: 5px}
            #out{margin-bottom:100px;}
		</style>
	</head>
	<body>
		<div>
		   <h2>默认评星</h2>
		   <div id="star"></div>
		   <p>
		   	$('#star').raty({</br/>
		       starOff: 'Resource/img/star-off-big.png',</br/>
		       starOn: 'Resource/img/star-on-big.png',</br/>
		       width:200</br/>
	        });</p>
		</div>
		
		<div>
		   <h2>有默认值的评星</h2>
		   <div id="valueStar"></div>
		   <p>
		   	$('#valueStar').raty({</br/>
		       starOff: 'Resource/img/star-off-big.png',</br/>
		       starOn: 'Resource/img/star-on-big.png',</br/>
		       width:200,</br/>
		       score:3
	        });</p>
		</div>
		
		<div>
		   <h2>有动态默认值的评星</h2>
		   <div id="dynamicValueStar" data-score='2'></div>
		   <p>
		   	$('#dynamicValueStar').raty({</br/>
		       starOff: 'Resource/img/star-off-big.png',</br/>
		       starOn: 'Resource/img/star-on-big.png',</br/>
		       width:200,</br/>
		       score:function(){</br/>
		       	return $(this).attr('data-score');</br/>
		       }</br/>
	        });</p>
		</div>
		
		<div>
		   <h2>改变星星的个数</h2>
		   <div id="changeStarNo" data-score='2'></div>
		   <p>
		   	$('#changeStarNo').raty({</br/>
		       starOff: 'Resource/img/star-off-big.png',</br/>
		       starOn: 'Resource/img/star-on-big.png',</br/>
		       width:200,</br/>
		       score:function(){</br/>
		       	return $(this).attr('data-score');</br/>
		       },</br/>
		       number:9</br/>
	        });</p>
		</div>
		
		<div>
		   <h2>ReadOnly星级显示</h2>
		   <div id="starReadyOnly" data-score='2'></div>
		   <p>
		   	$('#starReadyOnly').raty({</br/>
		       starOff: 'Resource/img/star-off-big.png',</br/>
		       starOn: 'Resource/img/star-on-big.png',</br/>
		       width:200,</br/>
		       readOnly:true
	        });</p>
		</div>
		
		<div>
		   <h2>半颗星显示</h2>
		   <div id="halfStar"></div>
		   <p>
		   	$('#starReadyOnly').raty({</br/>
		       starOff: 'Resource/img/star-off-big.png',</br/>
		       starOn: 'Resource/img/star-on-big.png',</br/>
		       width:200,</br/>
		       readOnly:true,
		       score:3.65
	        });</p>
		</div>
		
		<div id="out">
		   <h2>星星点击事件</h2>
		   <div id="starClick"></div>
		   <p>
		   	$('#starClick').raty({</br/>
		       starOff: 'Resource/img/star-off-big.png',</br/>
		       starOn: 'Resource/img/star-on-big.png',</br/>
		       width:200,</br/>
		       readOnly:true,
		       score:3.65,
		       click:function(score, event){
		       	   alert("id:"+$(this).attr("id")+"\n值:"+score+"\n事件:"+event.type);
		       }
	        });</p>
		</div>
		
		<div id="test">
			
			
		</div>
	</body>

</html>
<script type="text/javascript">
	$('#star').raty({
		starOff: 'Resource/img/star-off-big.png',
		starOn: 'Resource/img/star-on-big.png',
		width:200
	});
	
	$('#valueStar').raty({
		starOff: 'Resource/img/star-off-big.png',
		starOn: 'Resource/img/star-on-big.png',
		width:200,
		score:3
	});
	
	$('#dynamicValueStar').raty({
		starOff: 'Resource/img/star-off-big.png',
		starOn: 'Resource/img/star-on-big.png',
		width:200,
		score:function(){
		   return $(this).attr('data-score');
		}
	});
	
	$('#changeStarNo').raty({
		starOff: 'Resource/img/star-off-big.png',
		starOn: 'Resource/img/star-on-big.png',
		width:300,
		score:function(){
		   return $(this).attr('data-score');
		},
		number:9
	});
	
	$('#starReadyOnly').raty({
		starOff: 'Resource/img/star-off-big.png',
		starOn: 'Resource/img/star-on-big.png',
		width:300,
		readOnly:true,
		score:3
	});
	
	$('#halfStar').raty({
		starOff: 'Resource/img/star-off-big.png',
		starOn: 'Resource/img/star-on-big.png',
		starHalf:'Resource/img/star-half-big.png',
		width:300,
		readOnly:true,
		score:3.66
	});
	
	$('#starClick').raty({
		starOff: 'Resource/img/star-off-big.png',
		starOn: 'Resource/img/star-on-big.png',
		starHalf:'Resource/img/star-half-big.png',
		width:300,
		score:3.66,
		click:function(score, event){
		   alert("id:"+$(this).attr("id")+"\n值:"+score+"\n事件:"+event.type);
		}
	});
	
</script>

效果图如下所示:




源代码下载地址:http://download.csdn.net/detail/u013059555/9722412

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

BruceCheng夏夏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值