我的网站是gapagap.com,当我向下滚动浏览帖子时,它会加载更多帖子,但其中有一个“投票”功能,点击时有时适用于某些帖子,有时不适用于随机帖子。这是代码片段..
索引文件
<div id="entries-content" class="list">
<ul id="entries-content-ul" class="col-1">
{section name=i loop=$posts}
{include file="posts_bit.tpl"}
{/section}
{literal}
<script type="text/javascript">
$(document).ready(function(){
//calling header function to set the active tab state
headerTabChange('hot');
var tpage = 2;
function lastAddedLiveFunc()
{
$('div#lastPostsLoader').html('');
$.get("{/literal}{$baseurl}/{literal}indexmore.php?page="+tpage, function(data){
if (data != "") {
$(".col-1").append(data);
}
$('div#lastPostsLoader').empty();
});
};
$(window).scroll(function(){
var wintop = $(window).scrollTop(), docheight = $(document).height(), winheight = $(window).height();
var scrolltrigger = 0.95;
if ((wintop/(docheight-winheight)) > scrolltrigger) {
lastAddedLiveFunc();
tpage = tpage+1;
$('#backtotop').show();
}
});
});
</script>
{/literal}
</ul>
<div id="lastPostsLoader"></div>
</div>
</div>
{include file='right.tpl'}
{include file='vote_js.tpl'}
这是 vote_js.tpl 的代码:
{literal}
<script type="text/javascript">
$('.vote').click(function(){
if( $(this).hasClass('loved')){
$(this).removeClass('loved');
likedeg(-1,$(this).attr('rel'));
}else{
likedeg(1,$(this).attr('rel'));
$(this).addClass('loved');
}
});
function likedeg(x,p){
jQuery.ajax({
type:'POST',
url:'{/literal}{$baseurl}{literal}'+ '/likedeg.php',
data:'art='+x+'&pid=' + p,
success:function(e){
$('#love_count_'+p).html(e);
}
});
}
</script>
{/literal}
这是另一个在post.tpl中具有投票功能的代码
<li>
{if $smarty.session.USERID ne ""}
<a class="vote love {insert name=get_fav_class value=var PID=$posts[i].PID}" id="post_love_{$posts[i].PID}" rel="{$posts[i].PID}" href="javascript:void(0);"><span>{$lang144}</span></a>
{else}
<a class="vote love " id="post_love_{$posts[i].PID}" rel="{$posts[i].PID}" href="{$baseurl}/login"><span>{$lang144}</span></a>
{/if}
</li>
投票功能在function.php中
function insert_get_fav_status($var)
{
global $conn;
$query="SELECT count(*) as total FROM posts_favorited WHERE USERID='".mysql_real_escape_string($_SESSION[USERID])."' AND PID='".intval($var[PID])."'";
$executequery=$conn->execute($query);
$total = $executequery->fields[total];
//echo $total.'<br />';
//var_dump($var);
return intval($total);
}
function insert_get_fav_class($var)
{
global $conn;
$query="SELECT count(*) as total FROM posts_favorited WHERE USERID='".mysql_real_escape_string($_SESSION[USERID])."' AND PID='".intval($var[PID])."'";
$executequery=$conn->execute($query);
$total = $executequery->fields[total];
//echo $total.'<br />';
//var_dump($var);
if (intval($total) == 1) return("loved");
else return ("");
}
function insert_get_unfav_status($var)
{
global $conn;
$query="SELECT count(*) as total FROM posts_unfavorited WHERE USERID='".mysql_real_escape_string($_SESSION[USERID])."' AND PID='".intval($var[PID])."'";
$executequery=$conn->execute($query);
$total = $executequery->fields[total];
return intval($total);
}
function insert_get_fav_count($var)
{
global $conn;
$query="SELECT count(*) as total FROM posts_favorited WHERE PID='".intval($var[PID])."'";
$executequery=$conn->execute($query);
$total = $executequery->fields[total];
return intval($total);
}
请理解我是一名 PHP 开发人员。我对 JAVASCRIPT 和 JQUERY 的了解为零。