这是非常容易使用,只需复制粘贴代码。您可以在背景中使用自己的星形图像。
我创建了一个变量var userRating
。你可以使用这个变量来从星星获得价值。
享受!:)
CSS
.rating {
float:left;
width:300px;
}
.rating span { float:right; position:relative; }
.rating span input {
position:absolute;
top:0px;
left:0px;
opacity:0;
}
.rating span label {
display:inline-block;
width:30px;
height:30px;
text-align:center;
color:#FFF;
background:#ccc;
font-size:30px;
margin-right:2px;
line-height:30px;
border-radius:50%;
-webkit-border-radius:50%;
}
.rating span:hover ~ span label,
.rating span:hover label,
.rating span.checked label,
.rating span.checked ~ span label {
background:#F90;
color:#FFF;
}
HTML
<div class="rating">
<span><input type="radio" name="rating" id="str5" value="5"><label for="str5"></label></span>
<span><input type="radio" name="rating" id="str4" value="4"><label for="str4"></label></span>
<span><input type="radio" name="rating" id="str3" value="3"><label for="str3"></label></span>
<span><input type="radio" name="rating" id="str2" value="2"><label for="str2"></label></span>
<span><input type="radio" name="rating" id="str1" value="1"><label for="str1"></label></span>
</div>
的Javascript
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// Check Radio-box
$(".rating input:radio").attr("checked", false);
$('.rating input').click(function() {
$(".rating span").removeClass('checked');
$(this).parent().addClass('checked');
});
$('input:radio').change(
function(){
var userRating = this.value;
alert(userRating);
});
});
</script>
步骤1:把它扔掉。到页面顶部的一堆链接不是表单控件的基础。第2步:您想从五个组中挑选一个选项,以便找到建立在单选按钮上的内容,例如[我通过Google找到的这个示例](http://www.sitepoint.com/jquery-star-rating/) #fig_star_sprite)。 – Quentin
@Quentin使这个答案,所以我可以给你一个正确的投票 –
为CSS只评分系统访问:http://stackoverflow.com/questions/23081194/how-to-create-rating-system-using-only -css/23081284#23081284 – 4dgaurav