gpt4 book ai didi

jQuery 分页 - 页数错误

转载 作者:行者123 更新时间:2023-12-01 01:16:42 26 4
gpt4 key购买 nike

我正在尝试在 rss 解析器中创建分页功能。快要工作了。只有最后一页是错误的。 See fiddle here 。最后一页显示 11-10。这是为什么?目前提要中有 10 个项目,因此在此示例中应该只有两页,而不是三页 - 并且在第二页上,应隐藏“下一页”按钮。

这是哪里出了问题吗?

if (numEntriesReturned+1-oRssConfig.contempOffset>0 && oRssConfig.contempOffset<100-oRssConfig.maxItems) $('#btnNext').css("display", "block");
else $('#btnNext').css("display", "none");

最佳答案

几个小时后,我完全重写了脚本。这应该可以使用 Zazar 的 zRSSFeed 插件加载 RSS 提要并对其进行分页。我评论了大多数函数,以便您可以看到并理解正在发生的事情,希望如此!

特点:
轻松选择要显示的“每页提要”。
轻松输入 RSS 源的链接。
下一个和上一个按钮在需要时出现/消失。
在每页上自动显示 Feed 计数。 示例:“1 of 5”

看看这个 Fiddle看看它的实际效果!
有疑问吗?

JQuery 脚本

// Editable Values
var feedlink = 'http://feeds.reuters.com/reuters/oddlyEnoughNews'; // Set Feed Location
var fpp = 4; // Choose how many feeds per page to display (fpp = Feeds Per Page)
var feedview = '#RSSview'; // Choose where to diplay the RSS Feed

// Initial Variables ( Do Not Edit )
var feeds = null; // Variable to hold total feed count
var totalpages = null; // Variable to hold total pages
var currentpage = null; // Variable to hold Current Page being Displayed
var lastpagefeeds = null; // Variable to hold Amount of Feeds on the Last Page
var firstof = null; // Variable to hold First Feed Display - Example: 3 of ?
var lastof = null; // Variable to hold Last Feed Display - Example: ? of 10
var feedoffset = 1; // Set Initial Feed Offset

///////////////////
// RSS Functions //
///////////////////

// Calulate Feed Count Display
function displayfeedcount(){
// Set 'First Of ???'
firstof = feedoffset;
// Set '??? of Last'
if(currentpage == Math.ceil(totalpages)){ lastof = feeds; }else{ lastof = (firstof + fpp) - 1;}
$('#offsetDispl').html( firstof + ' of ' + lastof); // Display Feed Count ' First of Last'
}

// Load Initial Feeds on Page 1
function initialfeeds(){
$(feedview).rssfeed( feedlink , { limit: fpp , offset: 0 }); // Load Initial Set of Feeds
currentpage = 1; // Set Current Page to 1
displayfeedcount(); // Trigger the Display of Feedcount - Example: '1 of 5'
}

// Calculate Total Pages
function calculatepages(){
totalpages = feeds / fpp; // Total Page Calculation
console.log( 'Total Pages: ' + totalpages); // Log - For Testing Purposes Only - Delete if Desired
initialfeeds(); // Trigger Initial Display of Feeds
}

// Determine if the NextBtn should be shown on load
function showbuttons(){
if ( feeds > fpp ){ $('#btnNext').show(); } // Evaluate 'Next Button' Visibility
}

// Determine Total Feed Count
function feedcount() {
feeds = arguments[1]; // Set Feed Count to Variable 'feeds'
console.log( 'Total Feeds: ' + feeds ); // Log - For Testing Purposes Only - Delete if Desired
showbuttons(); // Trigger Initial Button Display
calculatepages(); // Trigger Total Page Calculation
}

// Function to Show Next Page
function nextpage(){
currentpage = currentpage + 1; // Set New Current Page
feedoffset = feedoffset + fpp ; // Set New Feed Offset
console.log('Current Page is: ' + currentpage); // Log - For Testing Purposes Only - Delete if Desired
console.log('Feed Offset is: ' + feedoffset ); // Log - For Testing Purposes Only - Delete if Desired
$(feedview).rssfeed( feedlink , { limit: fpp , offset: feedoffset }); // Load Next Set of Feeds
if( currentpage >= totalpages ){ $('#btnNext').hide();} // Evaluate 'Next Button' Visibility
if( currentpage > 1){ $('#btnPrev').fadeIn('250');} // Evaluate 'Previous Button' Visibility
displayfeedcount(); // Display Feed Count ' ??? of ??? '
}

// Function to Show Previous Page
function prevpage(){
currentpage = currentpage - 1; // Set New Current Page
feedoffset = feedoffset - fpp ; // Set New Feed Offset
console.log('Current Page is: ' + currentpage); // Log - For Testing Purposes Only - Delete if Desired
console.log('Feed Offset is: ' + feedoffset ); // Log - For Testing Purposes Only - Delete if Desired
$(feedview).rssfeed( feedlink , { limit: fpp , offset: feedoffset });
if( currentpage <= totalpages ){ $('#btnNext').fadeIn('250');} // Evaluate 'Next Button' Visibility
if( currentpage <= 1){ $('#btnPrev').hide();} // Evaluate 'Previous Button' Visibility
displayfeedcount(); // Display Feed Count ' ??? of ??? '
}

// Bind Previous and Next Button Clicks
$('#btnPrev').on('click', prevpage); // Bind the PrevPage Function
$('#btnNext').on('click', nextpage); // Bind the NextPage Function

// Retrieve Total Feeds
$('#hidden').rssfeed( feedlink , {}, feedcount);
// Make sure this divider exists on the page body >>> <div id="hidden" style='display:none;'></div>

关于jQuery 分页 - 页数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13309434/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com