我正在尝试为无限滚动中的每个新元素添加投票功能。我设法使投票功能正常工作,但这不适用于向下滚动页面时加载的新元素。
粘贴地址:http://pastebin.com/0eNYDXrm
我在下面附上了我的代码。任何帮助或建议将不胜感激......非常感谢!
<script type="text/javascript">
$('.protected-post-form').center();
$('#content').infinitescroll({
debug: false,
loading: {},
state: {
currPage: "1"
},
nextSelector: "div.navigation a:first",
navSelector: "div.navigation",
contentSelector: "#content",
itemSelector: "#content div.post",
pathParse: ["<?php echo $_SERVER["HTTP_HOST "] . $_SERVER["REQUEST_URI "] ?>page/", "/"]
}, function() {
window.setTimeout(infinite_scroll_callback(), 1);
});
function applyvote(elements) {
$(elements).each(
$(".vote a").click(
function() {
var some = jQuery(this);
var thepost = jQuery(this).attr("post");
var theuser = jQuery(this).attr("user");
jQuery.post("<?php bloginfo('template_url'); ?>/vote.php", {
user: theuser,
post: thepost
}, function(data) {
var votebox = ".vote" + thepost + " span";
jQuery(votebox).text(data);
});
});
});
}
$(elem).infinitescroll(options, applyvote(arrayOfNewElems));
});
</script>