嫌麻烦的也可以:点击下载
HTML:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><script src="common/js/jquery.js" type="text/javascript"></script><script language="JavaScript" type="text/javascript">jQuery(function($) { //这两个是鼠标放上去的效果 $(".zhan").hover(function(){ $(this).children("b").toggle(); }); $(".cai").hover(function(){ $(this).children("b").toggle(); }); }); </script><script type="text/javascript"> <!--这两个点击事件可以改进的,因为事件问题,所以就弄了两个点击事件 $(document).ready(function(e) { //点赞(给力) $('.zhan').click(function(){ var zhan=$(this); var left = parseInt($(this).offset().left)+10, top = parseInt($(this).offset().top)-10, obj=$(this); $(this).append('<div id="zhan"><b>+1<\/b></\div>'); $('#zhan').css({'position':'absolute','z-index':'1', 'color':'#C30','left':left+'px','top':top+'px'}).animate({top:top-10,left:left+10},'slow',function(){ $(this).fadeIn('fast').remove(); var Num = parseInt(obj.find('span').text()); Num++; obj.find('span').text(Num); });$.ajax({ url:"ajax.php?action=zan", type:"post", data:"answer_id="+$(this).attr("alt"), success:function(datas){ zhan.unbind('click'); zhan.parent().parent().siblings().children().children().unbind('click'); zhan.parent().parent().siblings().children().children().attr("class","evaluate-inner"); zhan.attr("class","evaluate-inner"); } }); }); //踩(不给力) $('.cai').click(function(){ var cai=$(this); var left = parseInt($(this).offset().left)+10, top = parseInt($(this).offset().top)-10, obj=$(this); $(this).append('<div id="cai"><b>-1<\/b></\div>'); $('#cai').css({'position':'absolute','z-index':'1', 'color':'#7DAAD5','left':left+'px','top':top+'px'}).animate({top:top-10,left:left+10},'slow',function(){ $(this).fadeIn('fast').remove(); var Num = parseInt(obj.find('span').text()); Num--; obj.find('span').text(Num); }); $.ajax({ url:"ajax.php?action=cai", type:"post", data:"answer_id="+$(this).attr("alt"), success:function(datas){ cai.unbind('click'); cai.parent().parent().siblings().children().children().unbind('click'); cai.parent().parent().siblings().children().children().attr("class","evaluate-inner"); cai.attr("class","evaluate-inner"); } }); }); }); //--></script><!--给力开始--><span data-evaluate="0" id="evaluate-1908165795" class="evaluate" alog-action="qb-zan-btn"> <span class="evaluate-outer"><!-----判断对应的回答的id是否在自己创建的存储赞和踩数据的php文件,如果赞或者踩存在一个的话就不能再单击----><span class="evaluate-inner {OVOV:if $answer_datas.ans_id|in_array:$zan_list or $answer_datas.ans_id|in_array:$cai_list/}{OVOV:else/}zhan{OVOV:/if/}" alt="{OVOV:$answer_datas.ans_id/}"> <b style="display:none" class="evaluate-tip evaluate-num-fixed">给力</b> <b class="evaluate-num evaluate-num-fixed"><span>{OVOV:$answer_datas.goods/}</span></b> </span> </span> </span><!--不给力开始--><span data-evaluate="0" id="evaluate-bad-1908165795" class="evaluate evaluate-bad" alog-action="qb-evaluate-outer"> <span class="evaluate-outer"> <span class="evaluate-inner {OVOV:if $answer_datas.ans_id|in_array:$zan_list or $answer_datas.ans_id|in_array:$cai_list/}{OVOV:else/}cai{OVOV:/if/}" alt="{OVOV:$answer_datas.ans_id/}"> <b style="display: none;" class="evaluate-tip evaluate-num-fixed">不给力</b> <b class="evaluate-num evaluate-num-fixed" style="display: inline-block;"><span>{OVOV:$answer_datas.bads/}</span></b> </span> </span> </span><!--评论回答开始-->
<?php $action=$_GET['action'];//获取get方式传过来的actionrequire_once("array/ovovsys_zan.php");switch($action){ case 'detail': /*****赞开始****/ $zan_list = json_decode(str_replace("'",'"',$zan_json),true); $zan_lists=array(); foreach($zan_list as $key=>$value){ if($value['uid']==$uid){ $zan_lists[]=$value['answer_id']; } } $smarty->assign('zan_list',$zan_lists);//查询当前登录的会员的uid对应的点赞的回答 /*****赞结束****/ /*****踩开始****/ $cai_list = json_decode(str_replace("'",'"',$cai_json),true); $cai_lists=array(); foreach($cai_list as $key=>$value){ if($value['uid']==$uid){ $cai_lists[]=$value['answer_id']; } } $smarty->assign('cai_list',$cai_lists);//查询当前登录的会员的uid对应的踩的回答 /*****踩结束****/ $smarty->display('自己的静态页面'); exit(); break;}?>
ajax文件:
<?php require_once("array/ovovsys_zan.php");//这里引用array文件夹中的数组文件$action=trim($_GET['action']);if(empty($action)){ echo '<font color=red>参数错误!';exit();}switch($action){ case 'zan'://点赞(给力) //$zan_json是数组文件中设置的数组变量,存的是json数据----1 $zan_array = json_decode(str_replace("'",'"',$zan_json),true); //获取当前的会员的uid-----2 $user_answer['uid']=$uid; //获取对应的赞的回答的id----2 $user_answer['answer_id']=$_POST['answer_id']; //将会员的uid和答案的id一块的数组放到指定的数组中----3 $zan_array[]=$user_answer; $config_path = 'shuzu/ovovsys_zan.php'; if(!file_exists($config_path)){ $Base->ErrorMsg('文件错误:shuzu/ovovsys_zan.php 不存在!');exit(); } //将指定的数组转换成json数据,并且将双引号转换成单引号,不然放到数组文件中后会出错----4 $zan_new_json = str_replace('"',"'",json_encode($zan_array)); $fp = @fopen($config_path,'r+'); if(!$content = @fread($fp,filesize($config_path))){ $Base->ErrorMsg('无法读取shuzu/ovovsys_zan.php文件!');exit(); } //执行替换,将数组文件中对应的json数据----5 $content = str_replace("\$zan_json = \"{$zan_json}\"","\$zan_json = \"{$zan_new_json}\"",$content); $fp = @fopen($config_path,'w+'); @fwrite($fp,$content); //修改对应的数据表中的数据----5 $Db->ThisQuery("update `".$db_prefix."ask_answers` set `goods`=`goods`+1 where `ans_id`=".$user_answer['answer_id'].""); exit(); break; case 'cai'://踩(不给力) $cai_array = json_decode(str_replace("'",'"',$cai_json),true); $user_answer['uid']=$uid; $user_answer['answer_id']=$_POST['answer_id']; $cai_array[]=$user_answer; $config_path = 'shuzu/ovovsys_zan.php'; if(!file_exists($config_path)){ $Base->ErrorMsg('文件错误:shuzu/ovovsys_zan.php 不存在!');exit(); } $cai_new_json = str_replace('"',"'",json_encode($cai_array)); $fp = @fopen($config_path,'r+'); if(!$content = @fread($fp,filesize($config_path))){ $Base->ErrorMsg('无法读取shuzu/ovovsys_zan.php文件!');exit(); } $content = str_replace("\$cai_json = \"{$cai_json}\"","\$cai_json = \"{$cai_new_json}\"",$content); $fp = @fopen($config_path,'w+'); @fwrite($fp,$content); $Db->ThisQuery("update `".$db_prefix."ask_answers` set `bads`=`bads`-1 where `ans_id`=".$user_answer['answer_id'].""); exit(); break;}?>
对应的数据文件(因为创建数据库时没有创建踩和赞的再断,所以这里就用php文件存变量的方式保存了一下答案对应的赞和踩的数据,其中包含用户的id和答案的id)
<?php $zan_json = "";$cai_json = "";?>你没看错,就是两个变量
如果嫌复制着麻烦的话,也可以点击下载压缩文件,亲,不要积分的哟!

在PHP中,trait適用於需要方法復用但不適合使用繼承的情況。 1)trait允許在類中復用方法,避免多重繼承複雜性。 2)使用trait時需注意方法衝突,可通過insteadof和as關鍵字解決。 3)應避免過度使用trait,保持其單一職責,以優化性能和提高代碼可維護性。

依賴注入容器(DIC)是一種管理和提供對象依賴關係的工具,用於PHP項目中。 DIC的主要好處包括:1.解耦,使組件獨立,代碼易維護和測試;2.靈活性,易替換或修改依賴關係;3.可測試性,方便注入mock對象進行單元測試。

SplFixedArray在PHP中是一種固定大小的數組,適用於需要高性能和低內存使用量的場景。 1)它在創建時需指定大小,避免動態調整帶來的開銷。 2)基於C語言數組,直接操作內存,訪問速度快。 3)適合大規模數據處理和內存敏感環境,但需謹慎使用,因其大小固定。

PHP通過$\_FILES變量處理文件上傳,確保安全性的方法包括:1.檢查上傳錯誤,2.驗證文件類型和大小,3.防止文件覆蓋,4.移動文件到永久存儲位置。

JavaScript中處理空值可以使用NullCoalescingOperator(??)和NullCoalescingAssignmentOperator(??=)。 1.??返回第一個非null或非undefined的操作數。 2.??=將變量賦值為右操作數的值,但前提是該變量為null或undefined。這些操作符簡化了代碼邏輯,提高了可讀性和性能。

CSP重要因為它能防範XSS攻擊和限制資源加載,提升網站安全性。 1.CSP是HTTP響應頭的一部分,通過嚴格策略限制惡意行為。 2.基本用法是只允許從同源加載資源。 3.高級用法可設置更細粒度的策略,如允許特定域名加載腳本和样式。 4.使用Content-Security-Policy-Report-Only頭部可調試和優化CSP策略。

HTTP請求方法包括GET、POST、PUT和DELETE,分別用於獲取、提交、更新和刪除資源。 1.GET方法用於獲取資源,適用於讀取操作。 2.POST方法用於提交數據,常用於創建新資源。 3.PUT方法用於更新資源,適用於完整更新。 4.DELETE方法用於刪除資源,適用於刪除操作。

HTTPS是一種在HTTP基礎上增加安全層的協議,主要通過加密數據保護用戶隱私和數據安全。其工作原理包括TLS握手、證書驗證和加密通信。實現HTTPS時需注意證書管理、性能影響和混合內容問題。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

記事本++7.3.1
好用且免費的程式碼編輯器

Dreamweaver CS6
視覺化網頁開發工具

Atom編輯器mac版下載
最受歡迎的的開源編輯器

SublimeText3漢化版
中文版,非常好用