需要引入jquery和raty的js,并且低版本的jquery可能会出现样式问题,或者点击没反应,可换高版本试试

raty文档及下载:

http://www.wbotelhos.com/raty/

把下载后文件夹中的lib下文件拷到自己项目下

js的选择星级评分插件-LMLPHP

 <script language="javascript" type="text/javascript" src="/JavaScript/jquery/jquery-2.1.0.min.js"></script>
<script language="javascript" type="text/javascript" src="/JavaScript/star/jquery.raty.js"></script> <div id="star"></div><!--> 显示星级用<-->
<div id="result" style="display:none;"></div><!--> 用户选中星级后的结果<--> <script>
$("#star").raty({
hints: ['1', '2', '3', '4', '5'],//鼠标悬浮在星星对应显示的值
path:"<%=PropertiesConfigureTools.getRESOURCE_URL()%>/JavaScript/star/images",//可以改成你存放的图片路径
starOff: 'star-off.png',//可以改变图片
starOn: 'star-on.png',//可以改变图片
size: 24,//div长度
target: '#result',//结果位置
targetKeep : true//属性设置为true,用户的选择值才会被保持在目标DIV中,否则只是鼠标悬停时有值,而鼠标离开后这个值就会消失。
half:true });
//将隐藏div的值发送给服务器即可
</script>
 <!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta content="width=device-width; initial-scale=1; maximum-scale=1" name="viewport">
<title></title> <link type="text/css" rel="stylesheet" href="demo/css/application.css">
<script type="text/javascript" src="demo/js/jquery.min.js"></script>
<script type="text/javascript" src="lib/jquery.raty.min.js"></script>
</head>
<body>
<div style="width:500px; margin:100px auto;">
<div class="demo">
<div id="function-demo" class="target-demo"></div>
<div id="function-hint" class="hint"></div>
</div>
<div class="demo">
<div id="function-demo1" class="target-demo"></div>
<div id="function-hint1" class="hint"></div>
</div>
</div>
<script type="text/javascript">
$(function() {
$.fn.raty.defaults.path = 'lib/img';
$('#function-demo').raty({
number: 3,//多少个星星设置
targetType: 'hint',//类型选择,number是数字值,hint,是设置的数组值
path : 'demo/img',
hints : ['差','一般','好'],
cancelOff : 'cancel-off-big.png',
cancelOn : 'cancel-on-big.png',
size : 24,
starHalf : 'star-half-big.png',
starOff : 'star-off-big.png',
starOn : 'star-on-big.png',
target : '#function-hint',
cancel : false,
targetKeep: true,
targetText: '请选择评分', click: function(score, evt) {
alert('ID: ' + $(this).attr('id') + "\nscore: " + score + "\nevent: " + evt.type);
}
}); $('#function-demo1').raty({
number: 10,//多少个星星设置
score: 2,//初始值是设置
targetType: 'number',//类型选择,number是数字值,hint,是设置的数组值
path : 'demo/img',
cancelOff : 'cancel-off-big.png',
cancelOn : 'cancel-on-big.png',
size : 24,
starHalf : 'star-half-big.png',
starOff : 'star-off-big.png',
starOn : 'star-on-big.png',
target : '#function-hint1',
cancel : false,
targetKeep: true,
precision : false,//是否包含小数
click: function(score, evt) {
alert('ID: ' + $(this).attr('id') + "\nscore: " + score + "\nevent: " + evt.type);
}
});
}); </script>
 全局改变设置:

 你可以全局更改上述提到的所有设置 $.fn.raty.defaults.OPTION = VALUE;. 该语句必须添加在插件绑定之前。
$.fn.raty.defaults.path = assets;
$.fn.raty.defaults.cancel = true; 参数: cancel : false // Creates a cancel button to cancel the rating.
cancelClass : 'raty-cancel' // Name of cancel's class.
cancelHint : 'Cancel this rating!' // The cancel's button hint.
cancelOff : 'cancel-off.png' // Icon used on active cancel.
cancelOn : 'cancel-on.png' // Icon used inactive cancel.
cancelPlace : 'left' // Cancel's button position.
click : undefined // Callback executed on rating click.
half : false // Enables half star selection.
halfShow : true // Enables half star display.
hints : ['bad', 'poor', 'regular', 'good', 'gorgeous'] // Hints used on each star.
iconRange : undefined // Object list with position and icon on and off to do a mixed icons.
mouseout : undefined // Callback executed on mouseout.
mouseover : undefined // Callback executed on mouseover.
noRatedMsg : 'Not rated yet!' // Hint for no rated elements when it's readOnly.
number : 5 // Number of stars that will be presented.
numberMax : 20 // Max of star the option number can creates.
path : undefined // A global locate where the icon will be looked.
precision : false // Enables the selection of a precision score.
readOnly : false // Turns the rating read-only.
round : { down: .25, full: .6, up: .76 } // Included values attributes to do the score round math.
score : undefined // Initial rating.
scoreName : 'score' // Name of the hidden field that holds the score value.
single : false // Enables just a single star selection.
space : true // Puts space between the icons.
starHalf : 'star-half.png' // The name of the half star image.
starOff : 'star-off.png' // Name of the star image off.
starOn : 'star-on.png' // Name of the star image on.
target : undefined // Element selector where the score will be displayed.
targetFormat: '{score}' // Template to interpolate the score in.
targetKeep : false // If the last rating value will be keeped after mouseout.
targetScore : undefined // Element selector where the score will be filled, instead of creating a new hidden field (scoreName option).
targetText : '' // Default text setted on target.
targetType : 'hint' // Option to choose if target will receive hint o 'score' type.
starType : 'img' // Element used to represent a star. 回调函数: $('div').raty('score'); // Get the current score. $('div').raty('score', number); // Set the score. $('div').raty('click', number); // Click on some star. $('div').raty('readOnly', boolean); // Change the read-only state. $('div').raty('cancel', boolean); // Cancel the rating. The last param force the click callback. $('div').raty('reload'); // Reload the rating with the current configuration. $('div').raty('set', { option: value }); // Reset the rating with new configurations. $('div').raty('destroy'); // Destroy the bind and give you the raw element. $('div').raty('move', number); // Move the mouse to the given score point position.
05-11 08:14