首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >jQuery分页-页数错误

jQuery分页-页数错误
EN

Stack Overflow用户
提问于 2012-11-09 21:57:44
回答 2查看 462关注 0票数 3

我正在尝试在rss解析器中实现分页功能。就快好用了。只有最后一页是错的。See fiddle here。最后一页显示11-10。为什么会这样呢?提要中当前有10个条目,因此在本例中应该只有两个页面,而不是三个页面-在第二个页面上,“下一步”按钮应该是隐藏的。

这是不是出了什么问题?

代码语言:javascript
运行
复制
if (numEntriesReturned+1-oRssConfig.contempOffset>0 && oRssConfig.contempOffset<100-oRssConfig.maxItems) $('#btnNext').css("display", "block");
    else $('#btnNext').css("display", "none");
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-09 22:46:22

几个小时后,我完全重写了脚本。这应该可以使用Zazar的zRSSFeed插件加载和分页RSS feed。我注释了大多数函数,这样你就可以看到并理解发生了什么,希望如此!

功能:

轻松选择要显示的“每页订阅”。

轻松输入指向RSS源的链接。

下一步和上一步按钮在需要时出现/消失。

在每页上自动显示进纸计数。示例:“第1个,共5个”

看看这个,看看它的实际效果!

有什么问题吗?

JQuery脚本

代码语言:javascript
运行
复制
// 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>   
票数 3
EN

Stack Overflow用户

发布于 2012-11-09 22:13:47

第一页的参数numEntriesReturned值为5,第二页的参数值为10。我认为当最后一页是满的时,它不是很有用。

如果您检测到最后一页是空的,也许您可以返回并移除按钮。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13309434

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档