最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jQuery+ajax實現(xiàn)文章點贊功能的方法

 更新時間:2015年12月31日 12:31:17   作者:flyfox  
這篇文章主要介紹了jQuery+ajax實現(xiàn)文章點贊功能的方法,涉及jQuery基于ajax無刷新post提交實現(xiàn)點贊功能的具體步驟與相關(guān)技巧,需要的朋友可以參考下

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

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

代碼很簡單,jQuery+php實現(xiàn)的。

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>

標(biāo)題都說了是無上限點贊的,So,麥?zhǔn)[告訴大家個小訣竅:

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

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

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

相關(guān)文章

最新評論

沙坪坝区| 阆中市| 二连浩特市| 惠来县| 龙州县| 博白县| 宣城市| 融水| 施甸县| 若羌县| 家居| 渝北区| 耒阳市| 鸡东县| 东兴市| 廊坊市| 康定县| 静宁县| 进贤县| 江达县| 宝清县| 巫山县| 舟曲县| 孝义市| 邯郸县| 军事| 安吉县| 永胜县| 霍州市| 呼和浩特市| 中山市| 安化县| 休宁县| 沂源县| 昭觉县| 郧西县| 永丰县| 安丘市| 玛曲县| 京山县| 桦川县|