网页上怎样表示动态用星星表示评分 的html+css,支持半颗星

网页上怎样表示动态用星星表示评分 的html+css,支持半颗星,第1张

你可以到这个地方去看一下

http://www.zhangxinxu.com/study/201308/hello-star.html

半星可以将图片换成灰色星星和半星然后多加5个A标签和label

html部分:

<table class="block">

<tr>

<td>

<span class="label">总体评价<em>*</em>:</span>

</td>

<td>

<div class="rating-wrap">

<ul class="rating-wrap-ul" onmouseout="onUlMouseOut()" onmouseover="onUlMouseOver()">

<li><a class="one-star" title="很差" data-hint="很差" href="javascript:clickStar(1)" onmouseover="onLiMouseOver(1)" onmouseout="onLiMouseOut()"></a></li>

<li><a class="two-stars" title="差" data-hint="差" href="javascript:clickStar(2)" onmouseover="onLiMouseOver(2)" onmouseout="onLiMouseOut()"></a></li>

<li><a class="three-stars" title="还行" data-hint="还行" href="javascript:clickStar(3)" onmouseover="onLiMouseOver(3)" onmouseout="onLiMouseOut()"></a></li>

<li><a class="four-stars" title="好" data-hint="好" href="javascript:clickStar(4)" onmouseover="onLiMouseOver(4)" onmouseout="onLiMouseOut()"></a></li>

<li><a class="five-stars" title="很好" data-hint="很好" href="javascript:clickStar(5)" onmouseover="onLiMouseOver(5)" onmouseout="onLiMouseOut()"></a></li>

</ul>

</div>

<span id="ratingText" class="active-hint" innerText=""></span>

</td>

</tr>

<tr>

<td>

<span class="label">评价<em>*</em>:</span>

</td>

<td>

<span class="note">(50-2000个字)</span>

<span id="textCount" class="note" innerText=""></span>

</td>

</tr>

<tr>

<td>

</td>

<td>

<textarea name="appraiseText" id="appraiseText" class="form-content-block form-textarea" rows="12"></textarea>

</td>

</tr>

<tr>

<td>

</td>

<td align="right">

<input type="button" value="提交" onclick="submitAppraise()">

<input type="button" value="关闭" onclick=" ">

</td>

</tr>

</table>

CSS:

body {

color: #333

font: normal normal normal 12px/1.5 Arial, 宋体, sans-serif

}

.block{

clear: both

margin-bottom:20px

margin-bottom: 10px

zoom: 1

padding:5px 11pxborder:1px solid #F5EEE8

padding-top:10pxmargin:0 10px 0

padding-bottom:20pxborder-bottom:1px dashed #E4E4E4

margin:10px autopadding:0border:none

}

.label{

float:right

margin-right: 10px

text-align: right

font-weight: normal

font-style:normal

width: 94px

}

em{

margin-right:5px

color:#c00

font-weight:bold

font-style:normal

margin-left:2px

}

.note {

color: #999

}

.form-textarea{

float: left

font-family: Tahoma, Geneva, sans-serif

margin-right: 5px

width: 598px

zoom: 1

font-family: inherit

font-size: 100%

-webkit-appearance: textarea

-webkit-box-orient: vertical

-webkit-rtl-ordering: logical

-webkit-user-select: text

background-color: white

border: 1px solid

cursor: auto

padding: 2px

resize: auto

white-space: pre-wrap

word-wrap: break-word

}

.rating-wrap {

display: inline-block

float: left

position: relative

top: -2px

width: 89px

height: 20px

margin-right: 5px

padding: 4px 0 0 5px

border: 1px solid #EFE0D7

background: #FFF9F1

z-index: 0

}

.rating-wrap ul,.rating-wrap a:hover {

background-image: url(../images/star_shade.png)

background-repeat: no-repeat

}

.rating-wrap ul {

-webkit-padding-start: 40px

display: block

list-style-type: disc

margin: 1em 0px

border: 0px

margin: 0px

outline: 0px

padding: 0px

list-style: none

position: relative

width: 85px

height: 16px

background-position: 0 -90px

z-index: 10

}

.rating-wrap li {

display: inline

}

.rating-wrap a {

zoom: 1

position: absolute

left: 0

top: 0

display: block

height: 16px

}

.rating-wrap .five-stars {

width: 84px

z-index: 10

background-position: 0 0px

}

.rating-wrap .four-stars {

width: 68px

z-index: 20

background-position: 0 -18px

}

.rating-wrap .three-stars {

width: 51px

z-index: 30

background-position: 0 -36px

}

.rating-wrap .two-stars {

width: 34px

z-index: 40

background-position: 0 -54px

}

.rating-wrap .one-star {

width: 17px

z-index: 50

background-position: 0 -72px

}

.active-hint{

color: #C00

float: left

padding-top:2px

font-weight: normal

font-style:normal

}

JS:

$(document).ready(function(){

$("#appraiseText").bind("keydown", function(){

var count = $("#appraiseText").val().length

if( count <= 200 ){

$("#textCount").html(" 还能输入<font color='green'><b>" + (200 - count) + "</b></font>个字")

}else{

$("#textCount").html(" 已超出<font color='red'><b>" + (count - 200) + "</b></font>个字")

}

})

})

var starValue=0

function onUlMouseOut(){

var y = -90 + starValue * 18

var position = "0 " + y + "px"

$(".rating-wrap-ul").css({

"background-position" : position

})

}

function onUlMouseOver(){

$(".rating-wrap-ul").css({

"background-position" : "0 -90px"

})

}

function onLiMouseOver(grade){

switch(grade){

case 1 : document.getElementById("ratingText").innerHTML="很差"break

case 2 : document.getElementById("ratingText").innerHTML="差"break

case 3 : document.getElementById("ratingText").innerHTML="还行"break

case 4 : document.getElementById("ratingText").innerHTML="好"break

case 5 : document.getElementById("ratingText").innerHTML="很好"break

default : document.getElementById("ratingText").innerHTML=""

}

}

function onLiMouseOut(){

onLiMouseOver(starValue)

}

function clickStar(grade){

starValue = grade

var y = -90 + grade * 18

var position = "0 " + y + "px"

$(".rating-wrap-ul").css({

"background-position" : position

})

}

希望能帮到你

用js 获取到后台给的html 然后再通过 动态构建 dom结构的方式来使用这些html

比如后台返回的html是:"hah...."var str="hah...."

那就 找到你想要放的地址id,比如是test那就是 $("#test").append(str) 然后就可以了。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7552833.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-07
下一篇 2023-04-07

发表评论

登录后才能评论

评论列表(0条)

保存