所以,问题是:即使loadedFirst值为false,也会发生这种情况。参见:
var lastA = $(".feedpost-pages > a").last();
var pageToLoad = lastA.attr("href");
var lodadedFirst = false;
$(".loadold").click(function () {
if (loadedFirst = true) {
lastA = lastA.prev();
var pageToLoad = lastA.attr("href");
alert("this is happening, but the loadedFirst value is false. How?");
}
$.get(pageToLoad, function (data) {
var postsContent = $(data).find(".post:not(:first)");
$(".feedpost-lastreplys").prepend(postsContent);
FormatPosts();
FixPosts();
countPosts();
loadedFirst = true;
});
});
答案 0 :(得分:1)
原因是:
var lodadedFirst = false
//----^ Remove the d.
第二个是:
if (loadedFirst = true) {
//--------------^ You are assigning and not comparing.
<强>最终强>
var lastA = $(".feedpost-pages > a").last();
var pageToLoad = lastA.attr("href");
var loadedFirst = false;
$(".loadold").click(function() {
if (loadedFirst == true) {
lastA = lastA.prev();
var pageToLoad = lastA.attr("href");
alert("this is happening, but the loadedFirst value is false. How?");
}
$.get(pageToLoad, function(data) {
var postsContent = $(data).find(".post:not(:first)");
$(".feedpost-lastreplys").prepend(postsContent);
FormatPosts();
FixPosts();
countPosts();
loadedFirst = true;
});
});
答案 1 :(得分:0)
更改
if (loadedFirst = true)
到
if (loadedFirst == true)
您要分配而不是比较。