二、使用教程
①、下载插件
https://github.com/wbotelhos/raty
②、导入文件
<script type="text/javascript" src="${ctx}/components/raty/jquery.raty.js"></script><link type="text/css" rel="stylesheet" href="${ctx}/components/raty/jquery.raty.css" />③、设置raty的全局图片路径
<form class="form-horizontal required-validate" method="post"> <div class="form-group"><label for="" class="col-md-2 control-label">评价星级</label><div class="col-md-10"> <div class="raty" name="level" data-bv-notempty>${good_comment.level}</div></div> </div><div class="form-group text-center "> <div class="col-md-11 col-md-offset-1"><button type="submit" class="btn btn-primary">保存商品评价</button> </div></div></form>1.创建一个div即可。
// 找到raty的div$("div.raty", $p).each(function() { var $this = $(this); YUNM.debug("div.raty" + $this.selector); // 获取初始化值 var score = $this.text(); // 置空 $this.text(""); // 获取name值,为后面bootstrap validator的filed var name = $this.attr("name"); // 初始化raty $this.raty({// 设置值score : score,size : 24,// The name of hidden field generated by RatyscoreName : name,// Re-validate the star rating whenever user change itclick : function(score, evt) { if ($this.parents().length > 0) {// 找到form表单var $form = $this.parents().find("form.required-validate", $p);if ($form.length > 0) { var data = $form.data("bootstrapValidator"); // 如果有值,设置表单验证通过 if (score > 0) {data.updateStatus(name, "VALID"); }} }} });});⑥、后台获取