落伍者站长论坛's Archiver

Berlu 发表于 2008-8-4 08:28

求一个星级评论的代码 有图:

[attach]28355[/attach]

点 星星 即可评分

imwolf 发表于 2008-8-4 08:45

*** 作者被禁止或删除 内容自动屏蔽 ***

SLYAR 发表于 2008-8-4 13:56

你的平台是什么?

重庆萤火虫 发表于 2008-8-4 15:03

这个代码我在站长站看过,只要点几颗星就评几星,原码不知道在哪里可以得到.

Berlu 发表于 2008-8-5 07:51

不知道用JS能不能实现?

gaoqun2 发表于 2008-8-5 08:45

JS实现了也是假的
不写数据库内容怎么保证?

sticker 发表于 2008-8-5 09:10

以下是源代码,有四个星星的图片因为不能加附件发不上来。[code]
<script language="JavaScript">
function star5(starid)
{
        src="images/";
        this.star_on_left = src+"star_on_left.gif";
        this.star_off_left = src+"star_off_left.gif";
        this.star_on_right = src+"star_on_right.gif";
        this.star_off_right = src+"star_off_right.gif";
        this.id = starid;
        this.point = 0;

        this.initial = starInitial;
        this.redraw = starRedraw;
        this.attach = starAttach;
        this.deattach = starDeAttach;
        this.doall = starDoall;
}

function starDoall(point)
{
        this.initial();
        this.attach();
        this.redraw(point);
}

function starInitial()
{
   var html = "<div style='float:left'><img id='star"+this.id+"_1' point='0.5' src='"+this.star_off_left+"'>";
   html += "<img id='star"+this.id+"_2' point='1' src='"+this.star_off_right+"'>";
   html += "<img id='star"+this.id+"_3' point='1.5' src='"+this.star_off_left+"'>";
   html += "<img id='star"+this.id+"_4' point='2' src='"+this.star_off_right+"'>";
   html += "<img id='star"+this.id+"_5' point='2.5' src='"+this.star_off_left+"'>";
   html += "<img id='star"+this.id+"_6' point='3' src='"+this.star_off_right+"'>";
   html += "<img id='star"+this.id+"_7' point='3.5' src='"+this.star_off_left+"'>";
   html += "<img id='star"+this.id+"_8' point='4' src='"+this.star_off_right+"'>";
   html += "<img id='star"+this.id+"_9' point='4.5' src='"+this.star_off_left+"'>";
   html += "<img id='star"+this.id+"_10' point='5' src='"+this.star_off_right+"'></div><div style='float:left; padding:0 8px;border-left:1px solid #ccc;line-height:15px;' id='show_"+this.id+"'></div>";   
   document.write(html);
}

function starAttach()
{
        for(var i=1;i<11;i++)
        {
                document.getElementById("star"+this.id+"_"+i).style.cursor="pointer";
                document.getElementById("star"+this.id+"_"+i).onmouseover= moveStarPoint;
                document.getElementById("star"+this.id+"_"+i).onmouseout= outStarPoint;
                document.getElementById("star"+this.id+"_"+i).starid= this.id;
                document.getElementById("star"+this.id+"_"+i).onclick= setStarPoint;
        }
}

function starDeAttach()
{
        for(var i=1;i<11;i++)
        {
                document.getElementById("star"+this.id+"_"+i).style.cursor="default";
                document.getElementById("star"+this.id+"_"+i).onmouseover = null;
                document.getElementById("star"+this.id+"_"+i).onmouseout = null;
                document.getElementById("star"+this.id+"_"+i).onclick= null;
        }
}

function starRedraw(point)
{
        this.point = point;
        if(parseInt(point)!=point) pointp = parseInt(point)+0.5;
        else pointp = point;
        var point2 = pointp*2;
        for(var i=1;i<11;i++)
        {
                if(i<= point2)
                        if(parseInt(i/2)*2==i)
                                document.getElementById("star"+this.id+"_"+i).src = this.star_on_right;
                        else
                                document.getElementById("star"+this.id+"_"+i).src = this.star_on_left;
            else
                        if(parseInt(i/2)*2==i)
                                document.getElementById("star"+this.id+"_"+i).src = this.star_off_right;
                        else
                                document.getElementById("star"+this.id+"_"+i).src = this.star_off_left;
        }
        document.getElementById("show_"+this.id).innerHTML = parseFloat(point).toFixed(1);
}

function moveStarPoint(evt)
{
        var pstar = evt?evt.target:event.toElement;
        var point = pstar.getAttribute("point");
        var starobj = new star5(pstar.starid);
        starobj.redraw(point);
}

function outStarPoint(evt)
{
        var pstar = evt?evt.target:event.srcElement;
        var starobj = new star5(pstar.starid);
        starobj.redraw(0);
}

function setStarPoint(evt)
{
        var pstar = evt?evt.target:event.srcElement;
        var starobj = new star5(pstar.starid);
        starobj.deattach();
        //set the form value
        document.getElementById(pstar.starid).value = pstar.getAttribute("point");;
}

//-->
</script>

<div>
        <form>       
        <script>var star = new star5('point');star.doall(2);</script>
        <input type='hidden' name='point' value="2" />
        <input type="submit" />
        </form>
</div>               

[/code]

sticker 发表于 2008-8-5 21:53

解答加分?

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.