麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發 > AJAX > 正文

jQuery+ajax實現文章點贊功能的方法

2024-09-01 08:33:40
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了jQuery+ajax實現文章點贊功能的方法,涉及jQuery基于ajax無刷新post提交實現點贊功能的具體步驟與相關技巧,需要的朋友可以參考下
 

本文實例講述了jQuery+ajax實現文章點贊功能的方法。分享給大家供大家參考,具體如下:

前幾日有童鞋問我索要本站右上角的點贊功能,麥蔥左思右想,決定把這功能分享出來,希望此功能對各位會帶來方便哦。

代碼很簡單,jQuery+php實現的。

jQuery代碼:

jQuery(document).ready(function($) {$(".zan").click(function(e){var $i=$(".zan i"), $b=$("<b>").text("+1"), n=parseInt($i.text());$b.css({"bottom":0,"z-index":999,});$i.text(n+1);$(".zan").append($b);$b.animate({"bottom":100,"opacity":0},1000,function(){$b.remove();});var d = setInterval(function(){clearInterval(d);if($(".zan b").length == 1){$.post("",{zan:$i.text()})}},1000)e.stopPropagation();});});

php代碼:

<?php$path = "zan.txt";if(isset($_POST['zan'])){$num = (int)$_POST['zan'];$save = fopen($path,"w");fwrite($save,$num);fclose($save);echo "good";exit();$zan = file_exists($path) ? intval(file_get_contents($path)) : 0;}?>

html代碼:

<div class="main"><div class="zan"><em>看官們給了 <i><?php echo $zan; ?></i> 個贊</em></div></div>

配上合適的css樣式:

.main { position: relative; font-size: 10pt; line-height: 18px; margin: 40px auto; width: 800px; height: 170px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none;}.zan { position: absolute; top: 20%; left: 45%; width: 160px; height: 110px; background: url("zan.jpg") center no-repeat; cursor: pointer; opacity: 0.85; }.zan:active { opacity: 1; }.zan em { position: absolute; color: #333; font-style: normal; bottom: -15px; width: 100%; text-align: center; }.zan i { font-style: normal; color: #E94F06; }.zan b { position: absolute; color: #E94F06; font-style: normal; bottom: -15px; width: 100%; text-align: center; }

就是這樣,簡單吧!

下面是完整代碼:

<?php$path = "zan.txt";if(isset($_POST['zan'])){$num = (int)$_POST['zan'];$save = fopen($path,"w");fwrite($save,$num);fclose($save);echo "good";exit();}$zan = file_exists($path) ? intval(file_get_contents($path)) : 0;?><!doctype html><html><head><meta charset="utf-8"><title>我要點贊</title><style>.main { position: relative; font-size: 10pt; line-height: 18px; margin: 40px auto; width: 800px; height: 170px; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; -o-user-select: none; user-select: none;}.zan { position: absolute; top: 20%; left: 45%; width: 160px; height: 110px; background: url("zan.jpg") center no-repeat; cursor: pointer; opacity: 0.85; }.zan:active { opacity: 1; }.zan em { position: absolute; color: #333; font-style: normal; bottom: -15px; width: 100%; text-align: center; }.zan i { font-style: normal; color: #E94F06; }.zan b { position: absolute; color: #E94F06; font-style: normal; bottom: -15px; width: 100%; text-align: center; }</style></head><body><div class="main"><div class="zan"><em>看官們給了 <i><?php echo $zan; ?></i> 個贊</em></div></div><script src="jquery.min.js"></script><script>jQuery(document).ready(function($) {$(".zan").click(function(e){var $i=$(".zan i"), $b=$("<b>").text("+1"), n=parseInt($i.text());$b.css({"bottom":0,"z-index":999,});$i.text(n+1);$(".zan").append($b);$b.animate({"bottom":100,"opacity":0},1000,function(){$b.remove();});var d = setInterval(function(){clearInterval(d);if($(".zan b").length == 1){$.post("",{zan:$i.text()})}},1000)e.stopPropagation();});});</script></body></html>

標題都說了是無上限點贊的,So,麥蔥告訴大家個小訣竅:

/* 怒贊 */jQuery.noConflict();function zan() {setInterval(function () {jQuery(".zan").click();zan();}, 600)}zan();

當然,如果你使用了加速樂防CC(麥蔥就是),怒贊請求量過多,會被屏蔽掉哦!除非你取消掉jQuery里的POST

希望本文所述對大家jQuery程序設計有所幫助。



注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 久久久久久久久久网站 | av在线观 | 久久精品在线免费观看 | 九九热国产在线 | 欧美一区2区三区4区公司二百 | 国产欧美精品综合一区 | 色综合久久久久久久久久久 | 欧美日韩亚洲成人 | 午夜精品福利在线观看 | 草久影院 | 欧美无极品 | 黄色片免费看看 | 久久精品黄 | 伊人99在线 | 51色视频 | 国产亚洲精品视频中文字幕 | 黄污网站在线观看 | 久久久久久久久日本理论电影 | 羞羞视频在线免费 | 最近日本电影hd免费观看 | 国产精品成aⅴ人片在线观看 | 欧美日韩精品一区二区三区不卡 | 青久草视频 | 草久免费 | 国产精品视频一区二区三区四 | 国产亚洲高清视频 | 精品久久久一二三区播放播放播放视频 | 久色乳综合思思在线视频 | 精品一区二区三区网站 | 一级毛片免费高清视频 | 天天色综合6 | 国产精品免费一区二区 | 日日夜av| 免费观看在线 | 精品一区二区免费 | 免费在线观看一级片 | 国产88久久久国产精品免费二区 | 亚洲一区二区在线 | 日韩剧情片 | 亚洲精品久久久久久久久久久 | 日韩毛片在线看 |