实现像百度文库那样的星星评分效果----javascript实现

html文件中主要代码:

<script src="../indexjs/search.js" type="text/javascript"></script>

 

 <span  onmouseout ="out()"> 

<img src="images/grayFiveStart.gif" id="giveScore1" οnclick="setscore(1)" onmousemove ="over(1)" style="cursor:pointer ; width:16px; height:16px;" alt="讨厌" /> 

<img src="images/grayFiveStart.gif" id="giveScore2" οnclick="setscore(2)" onmousemove ="over(2)" style="cursor:pointer; width:16px; height:16px;" alt="不喜欢" /> 

<img src="images/grayFiveStart.gif" id="giveScore3" οnclick="setscore(3)" onmousemove ="over(3)" style="cursor:pointer ; width:16px; height:16px;" alt="一般" /> 

<img src="images/grayFiveStart.gif" id="giveScore4" οnclick="setscore(4)" onmousemove ="over(4)" style="cursor:pointer; width:16px; height:16px;"  alt="喜欢" /> 

<img src="images/grayFiveStart.gif" id="giveScore5" οnclick="setscore(5)" onmousemove ="over(5)" style="cursor:pointer ; width:16px; height:16px;" alt="非常喜欢" /> 

<span class="b2c_star_note" id="commentScore">&nbsp;</span>                                      

</span>

<input type="hidden" id="bthidden" value="0" />

 

search.js文件中代码:

function setscore(score)

{

 var txtSearchFood = document.getElementById("bthidden" );

     txtSearchFood.value=score;

}

function out()

{

var txtSearchFood = document.getElementById("bthidden" );

 

if(txtSearchFood.value==0)

{

for(i=1;i<=5;i++)

{

  var txtSearchFood = document.getElementById("giveScore" + i.toString());

        txtSearchFood.src = "images/grayFiveStart.gif";

}

}

}

function over(score) {

var txtSearchFood = document.getElementById("bthidden" );

 

if(txtSearchFood.value>0)

{

return false;

}

    for (i = 1; i <= score; i++) {

        var txtSearchFood = document.getElementById("giveScore" + i.toString());

        txtSearchFood.src = "images/fiveStart.jpg";

    }

    for (i = 5; i > score; i--) {

        var txtSearchFood = document.getElementById("giveScore" + i.toString());

        txtSearchFood.src = "images/grayFiveStart.gif";

    }

    var tscore = document.getElementById("commentScore");

    // scoretext;

    switch (score) {

        case 1: scoretext = "很讨厌"; break;

        case 2: scoretext = "不喜欢"; break;

        case 3: scoretext = "一般"; break;

        case 4: scoretext = "喜欢"; break;

        case 5: scoretext = "非常喜欢"; break;

 

    } tscore.innerHTML = scoretext;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值