久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      jQuery+PHP實現(xiàn)購物商城常用的星級評分效果

      jQuery+PHP實現(xiàn)購物商城常用的星級評分效果

      jQuery+PHP實現(xiàn)購物商城常用的星級評分效果,我們在商城平臺購買商品后,會有個評分功能,本實例就來說說實現(xiàn)方法。

      jQuery+PHP實現(xiàn)購物商城常用的星級評分效果

      首先我們在.rate里面加入顯示的灰星星p#big_rate、亮星星p#big_rate_up、分數(shù)span#s及span#g和提示信息p#my_rate。
      接著我們寫一個獲取評分的方法get_rate() :

      function get_rate(rate) {      rate = rate.toString();      var s;      var g;      $("#g").show();      if (rate.length >= 3) {          s = 10;          g = 0;          $("#g").hide();      } else if (rate == "0") {          s = 0;          g = 0;      } else {          s = rate.substr(0, 1);          g = rate.substr(1, 1);      }      $("#s").text(s);      $("#g").text("." + g);      $(".big_rate_up").animate({          width: (parseInt(s) + parseInt(g) / 10) * 14,          height: 26      },      1000);      $(".big_rate span").each(function() {          $(this).mouseover(function() {              $(".big_rate_up").width($(this).attr("rate") * 14);              $("#s").text($(this).attr("rate"));              $("#g").text("");          }).click(function() {              var score = $(this).attr("rate");              $("#my_rate").html("您的評分:<span>" + score + "</span>");              $.ajax({                  type: "POST",                  url: "ajax.php",                  data: "score=" + score,                  success: function(msg) {                      //alert(msg);                      if (msg == 1) {                          $("#my_rate").html("<span>您已經(jīng)評過分了!</span>");                      } else if (msg == 2) {                          $("#my_rate").html("<span>您評過分了!</span>");                      } else {                          get_rate(msg);                      }                  }              });          })      }) $(".big_rate").mouseout(function() {          $("#s").text(s);          $("#g").text("." + g);          $(".big_rate_up").width((parseInt(s) + parseInt(g) / 10) * 14);      })  }

      然后直接調用該方法即可:

      get_rate(<?php echo $aver; ?>);

      ajax.php接收前端發(fā)送過來的分數(shù)值,通過cookie判斷用戶IP和評分時間,防止重復評分。

      $score = $_POST['score'];  if (isset($score)) {      $cookiestr = getip();      $time = time();      if (isset($_COOKIE['person']) && $_COOKIE['person'] == $cookiestr) {          echo "1";      } elseif (isset($_COOKIE['rate_time']) && ($time - intval($_COOKIE['rate_time'])) < 60) {          echo "2";      } else {          $query = mysql_query("update raty set voter=voter+1,total=total+'$score' where id=1");          $query = mysql_query("select * from raty where id=1");          $rs = mysql_fetch_array($query);          $aver = 0;          if ($rs) {              $aver = $rs['total'] / $rs['voter'];              $aver = round($aver, 1) * 10;          }          //設置COOKIE          setcookie("person", $cookiestr, time() + 3600 * 365);          setcookie("rate_time", time(), time() + 3600 * 365);          echo $aver;      }  }

      raty表結構:

      CREATE TABLE IF NOT EXISTS `raty` (      `id` int(11) NOT NULL auto_increment,      `voter` int(10) NOT NULL default '0' COMMENT '評分次數(shù)',     `total` int(11) NOT NULL default '0' COMMENT '總分',      PRIMARY KEY  (`id`)    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;

      最后記得在raty評分表里面加一條數(shù)據(jù)。

      本文來自php中文網(wǎng),php教程欄目,歡迎學習!

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號