博客 - JS/Ajax/AS

基于jQuery实现星级评分效果

仿照『口碑』的评星级效果做的一点小东西,测试下自己这段时间的学习成果···

看图知效果:

星级评分

预览效果:星级评分

下载文件:star-Level.rar

口碑的代码:starLevel-koubei.rar[提取自口碑网]

html

  1. <div class="selectStar">
  2. <ul class="clearfix">
  3.     <li>
  4.         <span class="red">*</span>
  5.         <span class="zi">服务  </span>
  6.         <span id="dpCont1" class="dpCont"></span>
  7.         <em id="dpStar1" class="">
  8.             <a href="#" id="1">1</a>
  9.             <a href="#" id="2">2</a>
  10.             <a href="#" id="3">3</a>
  11.             <a href="#" id="4">4</a>
  12.             <a href="#" id="5">5</a>
  13.         </em>
  14.     </li>
  15. </ul>
  16. </div>

javascript:

  1. $(function(){
  2.     var className;
  3.     var classID;
  4.     var dpText="";
  5.     var dpTextC="";
  6.    
  7.     $(".selectStar em a").bind("click",function(){
  8.         className = "selectS" + $(this).attr("id");
  9.         classID = $(this).parent().attr("id");
  10.         $(this).parent().removeClass().addClass(className);
  11.        
  12.         if($(this).attr("id") == 1 || $(this).attr("id") == 2) {dpTextC = "差评";}
  13.         if($(this).attr("id") == 3 || $(this).attr("id") == 4) {dpTextC = "中评";}
  14.         if($(this).attr("id") == 5) {dpTextC = "好评";}
  15.         $(this).parent().prev(".dpCont").text(dpTextC);
  16.        
  17.         return false;
  18.     })   
  19.     .bind("mouseover",function(){
  20.         if($(this).attr("id") == 1 || $(this).attr("id") == 2) {dpText = "差评";}
  21.         if($(this).attr("id") == 3 || $(this).attr("id") == 4) {dpText = "中评";}
  22.         if($(this).attr("id") == 5) {dpText = "好评";}
  23.         $(this).parent().removeClass().addClass("selectS" + $(this).attr("id"));
  24.         $(this).parent().prev(".dpCont").text(dpText);
  25.     })   
  26.     .bind("mouseout",function(){
  27.         $(this).parent().removeClass("selectS" + $(this).attr("id"));
  28.         if($(this).parent().attr("id") == classID){
  29.             $(this).parent().addClass(className);
  30.         }
  31.        
  32.         $(this).parent().prev(".dpCont").text(dpTextC);
  33.     });
  34. });

标签:

10 条评论 发表在“基于jQuery实现星级评分效果”上

  1. Fusdwets

    hmm… interesting thoughts.

    [回复]

  2. Nanjim

    怎么用? :em13: :em13: :em13: :em13: :em13: :em13:

    [回复]

  3. lei

    :em13:
    我想在 123.php页面获取用户评分值,存入是数据库。我该如何获取评分值呢????

    [回复]

    heluyao

    你可以弄个隐藏域,当评级状态改变的时候随之改变。
    然后php获取这个隐藏域的值,就很简单了

    [回复]

  4. 1111111

    有一个问题
    我在asp.net项目中只有第一个框框有效
    多个后面的都无效~~

    [回复]

    heluyao

    注意下代码中的ID,ID是不能重复的。dpCont1、dpStar1。

    [回复]

  5. hi

    有个问题,点击后,鼠标再去划过选项。
    除了最后次点击的选中外,其他的都清空了。评论语也显示为最后次点击的评论语。
    该如何解决?

    [回复]

    heluyao

    :em15: 才发现这个问题,你自己先找解决的办法吧!我暂时抽不出时间来。

    [回复]

  6. 酷库免费icon图标

    能不能让一个评论者只评论一次? 能的话就用了? 我想拿去直接使用~

    [回复]

    heluyao

    这个需要后端的支持!

    [回复]

写下您的看法

  • :em18:
  • :em12:
  • :em03:
  • :em08:
  • :em06:
  • :em05:
  • :em07:
  • :em15:
  • :em11:
  • :em16:
  • :em01:
  • :em17:
  • :em10:
  • :em13:
  • :em14:
  • :em02:
  • :em09:
  • :em04:

仅支持“a、abbr、strong、em、blockquote、code”几个简单的标签

使用腾讯微博登陆 使用新浪微博登陆