国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

帝國cms首頁列表頁實現點贊功能

2019-11-19 15:01:43
字體:
來源:轉載
供稿:網友

查看帝國cms建站程序新聞系統的內容頁模版代碼,找到頂一下的HTML代碼塊,如下所示:

<table border="0" align="center" cellpadding="0" cellspacing="0" class="digg"> <tr> <td class="diggnum" id="diggnum"><strong><script type="text/javascript" src="[!--news.url--]e/public/ViewClick/?classid=[!--classid--]&id=[!--id--]&down=5"></script></strong></td> </tr> <tr> <td class="diggit"><a href="JavaScript:makeRequest('[!--news.url--]e/public/digg/?classid=[!--classid--]&id=[!--id--]&dotop=1&doajax=1&ajaxarea=diggnum','EchoReturnedText','GET','');" rel="external nofollow" >來頂一下</a></td> </tr> </table> 

由以上代碼可知,當前的總頂數是通過動態腳本載入的方式實時輸出,而a標簽上的makeRequest()函數就是用來實現頂一下功能的方法。makeRequest()函數的第一個參數是請求地址并附帶參數數據,第二個參數是成功請求后執行的回調函數名,第三個參數指定以GET方式發送請求。了解實現的原理之后就很容易在網站其他頁面上實現頂一下(點贊)功能,以下給出實現方法的相關代碼。

例如我們需要在產品列表模板頁面上實現頂一下功能,那么首先就需要修改產品列表模板的代碼,以下是我修改后的列表模板代碼:

頁面模板內容

<!DOCTYPE html> <html lang="zh"> <head> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta charset="utf-8"> <title><?php echo ReturnClassAddField(0,"seotitle");?></title> <meta name="keywords" content="[!--pagekey--]"> <meta name="description" content="[!--pagedes--]"> <link rel="stylesheet" href="[!--news.url--]index/css/style.css" rel="external nofollow" > </head> <body> <div class="head_about">[!--temp.header--]</div> <div class="bannProOuter"><div class="bannPro"><ul><li><a class="current" href="<?=sys_ReturnBqClassname($class_r[1],9)?>" rel="external nofollow" ><?=$class_r[1][classname]?></a></li></ul></div></div> <div class="proOuter"><div class="proInner clearfix">   <div class="proSort">     <ul> [e:loop={"select classid,classname,classpath from phome_enewsclass where classid in (7,8,9,10,11) order by classid asc",0,24,0}] <?php if($bqno==5){   echo '<li class="lastChild">'; }else{   echo "<li>"; } $titleclass=""; if($bqr[classid]==$GLOBALS[navclassid]){   $titleclass="current"; } ?> <a href="<?=$bqsr[classurl]?>" rel="external nofollow" class="<?=$titleclass?>"><?=$bqr[classname]?></a></li> [/e:loop]     </ul>   </div>   <div class="selectNumberScreen"><div class="screenBox"><?=user_ShowFieldandChange()?></div></div>   <div class="proList clearfix"><ul>[!--empirenews.listtemp--]<!--list.var1-->[!--empirenews.listtemp--]</ul></div>   <div class="page2 txtC">[!--show.listpage--]</div> </div></div> [!--temp.footer--] <script type="text/javascript"> $(".proList .photo").hover(function(){$(this).find(".txt").stop().animate({height:"300px"},300);},function(){$(this).find(".txt").stop().animate({height:"0px"},300);}); </script> </body> </html> 

列表內容模板(list.var)

$nomar=""; if($no%4==0){$nomar=" class=/"nomar/"";}else{$nomar="";} if($r[titlepic]){$tpic=sys_ResizeImg($r[titlepic],300,300,1,"");}else{$tpic="/e/data/images/notimg.gif";} $listtemp='<li'.$nomar.'><div class="photo"><img src="'.$tpic.'"><a href="[!--titleurl--]" rel="external nofollow" rel="external nofollow" rel="external nofollow" ><div class="txt"><h3>查看<br>詳情</h3></div></a></div> <b><a href="[!--titleurl--]" rel="external nofollow" rel="external nofollow" rel="external nofollow" >[!--title--]([!--model--])</a></b> <a href="[!--titleurl--]" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="icon-thumbs-up" data-classid="[!--classid--]" data-id="[!--id--]"><em>[!--diggtop--]</em>人贊過</a></li>'; 最后在底部模板里或JS文件中加入以下js代碼,大功告成[html] view plain copy print?<script type="text/javascript"> $(".icon-thumbs-up").click(function(event){   event.preventDefault();   var mythis = $(this);   var classid = mythis.data("classid");   var id = mythis.data("id");   $.ajax({     type:"GET",     url:"[!--news.url--]e/public/digg/",     data:{"classid":classid,"id":id,"dotop":1,"doajax":1,"ajaxarea":"diggnum"},     dataType:"text",     success:function(data){       var reinfo = data.split("|");       if (reinfo.length != 1) {         if (reinfo[0] != "") {           mythis.find("em").html(reinfo[0]);         }         if (reinfo[2] != "") {           //var left = parseInt(mythis.offset().left)+20, top = parseInt(mythis.offset().top);           var left = 20, top = mythis.find("em").get(0).offsetHeight;           $(".zan").remove();           if (reinfo[2] == "謝謝您的支持") {             mythis.append('<div class="zan">+1 謝謝您的支持</div>');             //$("body").append('<div class="zan">+1 謝謝您的支持</div>');           }else{             mythis.append('<div class="zan">已贊</div>');             //$("body").append('<div class="zan">已贊</div>');           }           //"text-shadow":"0 1px 0 rgba(0,0,0,0.5)","font-family":"simsun"           $(".zan").css({"position":"absolute","z-index":"10","left":left+"px","top":-top+"px","color":"inherit"}).animate({top:-top-30},"slow",function(){$(this).fadeIn("fast").remove();});         }       }else{}     }   }); }); </script> 

總結

以上所述是小編給大家介紹的帝國cms首頁列表頁實現點贊功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 弋阳县| 抚远县| 晋城| 赞皇县| 西乌珠穆沁旗| 全椒县| 兰坪| 手游| 邵阳市| 龙南县| 阿城市| 工布江达县| 綦江县| 香港 | 平度市| 新兴县| 齐齐哈尔市| 会理县| 西吉县| 云阳县| 中牟县| 汕尾市| 敦化市| 孟津县| 天峻县| 商都县| 宝兴县| 饶阳县| 淮滨县| 日喀则市| 达拉特旗| 平潭县| 临沂市| 永仁县| 彩票| 岳西县| 洛隆县| 桂东县| 新营市| 平泉县| 鄱阳县|