首页 > 网站 > WEB开发 > 正文

JS评分系统,并提供源码下载

2024-04-27 14:03:45
字体:
来源:转载
供稿:网友

<div id="GradeVoteArea"> </div>
<div id="GradeVoteScore">请您评分</div>
<script language="javaScript">
/*
/////////////////////////////////////////////////////////////////////////////////////////////////
//评分系统 BY 王晓斌 2006-11-16
//    函数:
//        CreateVote(Max,Def)               创建平分星星数量 Max为总共多少星星,Def为默认分数
//        AddContent(sNA)                   添加平分内容sNA
//        GradeVoteImage1                   星星图片一
//        GradeVoteImage2                   星星图片二
//////////////////////////////////////////////////////////////////////////////////////////////////
*/
function GradeVote() {
        this.VoteMaxStar=1;
        this.VoteCounter=1;
        this.VoteContent=new Array();
        this.GradeVoteImage1="";
        this.GradeVoteImage2="";

        this.AddContent=function (sNA) {
                this.VoteContent["_"+this.VoteCounter]=sNA;
                this.VoteCounter++;
        }
        /*创建评分星星*/
        this.CreateVote=function (MaxStar,DefaultStar) {
                var i=1,j=1;
                var VoteImgHTML="";
                this.VoteMaxStar=MaxStar;
                for (i=1;i<=MaxStar;i++) {
                        VoteImgHTML+="<img id=/"_GradeVoteID"+i+"/" src=/""+(j<=DefaultStar ? this.GradeVoteImage1 : this.GradeVoteImage2)+"/" border=/"0/" onMouSEOver=/"WindowVote.HitVote('"+i+"');/" onClick=/"WindowVote.VoteSubmit('"+i+"');/">";
                        j++;
                }
                if (document.getElementById("GradeVoteArea")!=null) {
                        document.getElementById("GradeVoteArea").innerHTML=VoteImgHTML;
                }
                else {
                        alert("Object not found!!");
                }
        }
        /* http://bizhi.vevb.com/ 评分等级内容*/
        this.VoteScoreContent=function (sID) {
                var VoteContent=this.VoteContent["_"+sID];
                if (VoteContent=="undefined" || VoteContent==null) VoteContent="Not defined!!";
                return VoteContent;
        }
        /*鼠标放到星星上*/
        this.HitVote=function (sID) {
                var i=1;
                for (i=1;i<=sID;i++) {
                        document.getElementById("_GradeVoteID"+i).src=this.GradeVoteImage1;
                }
                document.getElementById("GradeVoteScore").innerHTML=this.VoteScoreContent(sID);
                sID++;
                for (i=sID;i<=this.VoteMaxStar;i++) {
                        document.getElementById("_GradeVoteID"+i).src=this.GradeVoteImage2;
                }
        }
        /*提交评分*/
        this.VoteSubmit=function (sID) {
                alert("您打了"+sID+"分!");
        }
}
var WindowVote = new GradeVote();
WindowVote.GradeVoteImage1="http://image.tudou.com/vivian/styles/vivi/star_mark_big.gif";
WindowVote.GradeVoteImage2="http://image.tudou.com/vivian/styles/vivi/star_unmark_big.gif";
WindowVote.CreateVote(5,3);
WindowVote.AddContent("没什么意思");
WindowVote.AddContent("一般了");
WindowVote.AddContent("还不错");
WindowVote.AddContent("挺好的");
WindowVote.AddContent("挺酷!");
</script>

从以下几个链接下载文件:Xun6 | Ziddu | 趣盘 | Brsbox


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表