当前位置导航:炫浪网>>网络学院>>网页制作>>JavaScript教程

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

<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!!");
                }
        }
        /* 评分等级内容*/
        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?http://www.xvna.com";
WindowVote.GradeVoteImage2="http://image.tudou.com/vivian/styles/vivi/star_unmark_big.gif?http://www.xvna.com";
WindowVote.CreateVote(5,3);
WindowVote.AddContent("没什么意思");
WindowVote.AddContent("一般了");
WindowVote.AddContent("还不错");
WindowVote.AddContent("挺好的");
WindowVote.AddContent("挺酷!");
</script>

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

相关内容
赞助商链接