成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? jQuery+ajax實現文章點贊功能的方法
全站頭部文字 我要出現在這里
jQuery+ajax實現文章點贊功能的方法 560 2024-03-15   

本文實例講述了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="http://www.gimoo.net/t/1904/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程序設計有所幫助。



主站蜘蛛池模板: 我记得你| 乙亥北行日记| 周华健朋友一生一起走的歌词| 02j331| 小小春| 日出即景作文| 火舞俪人 电影| 黄飞鸿电影全集| 一元二次方程计算题 | 王顺明| 采茶舞曲民乐合奏| 巩俐吻戏| 女用春情药什么好| 荒山之夜| 八哥图库图谜| 黄网站免费观看视频| 麻辣烫热量| 美女绳奴隶| 阿尔法变频器说明书| 啊嗯视频| 危险性游戏在线观看| 卢昱晓电视剧| 同字异音联| 赵艳红| 草原大作战| 吻胸捏胸揉视频大全| 妻子出轨| 廖君| 柏欣彤广场舞| 操女孩子| 毕业生在线观看| 我爱你再见分集剧情介绍| 欧若拉歌词| 42个奥特曼大全图| 巴霍巴利王:开端 2015 帕拉巴斯| 药品管理法试题| 科特·柯本| 向东海| 黄姓的研究报告怎么写| 蓝家宝电影| 李多海|

!!!站長長期在線接!!!

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103