php做五星评价系统,JavaScript五星评分制作

在很多地方都可以看到的五星评分设计,五星评分有很多好处,比如可以收集到用户对内容的评价,让用户参与进来,这是Web2.0的一个重要特征。

程序演示

这个效果主要体现在CSS和javascript的配合上。

JavaScript Code

var TB = function() {

var T$ = function(id) { return document.getElementById(id) }

var T$$ = function(r, t) { return (r || document).getElementsByTagName(t) }

var Stars = function(cid, rid, hid, config) {

var lis = T$$(T$(cid), 'li'), curA;

for (var i = 0, len = lis.length; i < len; i++) {

lis[i]._val = i;

lis[i].onclick = function() {

T$(rid).innerHTML = '' + (T$(hid).value = T$$(this, 'a')[0].getAttribute('star:value')) + '分 - ' + config.info[this._val];

curA = T$$(T$(cid), 'a')[T$(hid).value / config.step - 1];

};

lis[i].onmouseout = function() {

curA && (curA.className += config.curcss);

}

lis[i].onmouseover = function() {

curA && (curA.className = curA.className.replace(config.curcss, ''));

}

}

};

return {Stars: Stars}

}().Stars('stars2', 'stars2-tips', 'stars2-input', {

'info' : ['写得极差', '写得不怎么好', '写得一般吧', '写得不错', '写得非常好'],

'curcss': ' current-rating',

'step': 20

});

CSS Code

ul, li {margin: 0; padding: 0; border: 0;}

.shop-rating { height: 25px; overflow: hidden; zoom: 1; padding: 2px 0; position: relative; z-index: 999; font:12px Arial; color:#000; line-height:1.2em; }

.shop-rating span { height: 23px; display: block; line-height: 23px; float: left; }

.shop-rating span.title { width: 125px; text-align: right; margin-right: 5px; }

.shop-rating ul { float: left; }

.shop-rating .result { margin-left: 20px; padding-top: 2px; }

.shop-rating .result span { color: #ff6d02; }

.rating-level,

.rating-level a { background: url(../images/o_star.png) no-repeat scroll 1000px 1000px;}

.rating-level { background-position: 0px 0px; width: 120px; height: 23px; position: relative; z-index: 1000; }

.shop-rating .result em { color: #f60; font-family: arial; font-weight: bold; }

.rating-level li { display: inline; }

.rating-level a { line-height: 23px; height: 23px; position: absolute; top: 0px; left: 0px; text-indent: -999em; *zoom: 1; outline: none; }

.rating-level a.one-star { width: 20%; z-index: 6; }

.rating-level a.two-stars { width: 40%; z-index: 5; }

.rating-level a.three-stars { width: 60%; z-index: 4; }

.rating-level a.four-stars { width: 80%; z-index: 3; }

.rating-level a.five-stars { width: 100%; z-index: 2; }

.rating-level .current-rating, .rating-level a:hover {background-position:0 -28px}

.rating-level a.one-star:hover,.rating-level a.two-stars:hover,.rating-level a.one-star.current-rating,.rating-level a.two-stars.current-rating{background-position:0 -116px;}

.rating-level .three-stars .current-rating,.rating-level .four-stars .current-rating,.rating-level .five-stars .current-rating{background-position:0 -28px;}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值