jquery动态分页
我有这个脚本,允许显示 Bing 搜索结果: JsFiddle 演示
问题是它只能显示一次 50 个结果。所以我想做一个分页。到目前为止,我有这段代码,它允许显示结果的第二部分,其中 var WebOffset = "Web.Offset=0";
$("#page2").click(function() {
WebOffset = "Web.Offset=1";
var searchTerms = getSearch();
doSearch(searchTerms);
});
我的问题:我如何预测总共有多少结果,以便我现在知道要制作多少个分页号(div)。但更重要的是,这当然必须是“自动化”的。因此,代码必须根据 bing 结果总数显示一组 div(分页编号)。我真的不知道要开始解决这个问题。任何帮助表示赞赏。
I have this script which allows to display Bing search results: JsFiddle Demo
The problem is that it can only show up to 50 result at a time. So I want to make a pagination . So far I have this code which allows to display the second part of the results, with var WebOffset = "Web.Offset=0";
$("#page2").click(function() {
WebOffset = "Web.Offset=1";
var searchTerms = getSearch();
doSearch(searchTerms);
});
My question: How can I predict how many results there are in total so that I would now how many pagination numbers (divs) to make. But more important this of course has to be 'automated'. So the code would have to display a set of divs(pagination numbers) based on the bing results in total. I really have no idea were to begin solving this problem. Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您必须具有一些服务器端逻辑才能获取结果,因此您可以在提交搜索查询时请求结果数并存储它,或者,您可以通过每个页面请求获取该数字。另外,由于您似乎正在使用 jQuery,因此这应该很容易。
这两种情况可能如下所示:
第一:
第二次:
您可以看到,在第一种情况下,您必须在客户端存储总结果数。与第二个相反,在第二个中,您会在每个结果请求中收到它。
回家这有帮助。祝你有美好的一天!
Since you must have some server side logic in order to get the results, you can request the number of results when a search query is submitted and store it, or, you can get that number with each page request. Also, since it appears you're using jQuery, this should be easy.
Here is what these two scenarios could look like:
First:
And the second:
You can see that in the first scenario, you would have to store the total result count on the client side. As opposed to the second one, where you receive it with every result request.
Home this helps. Have a great day!