通过 jQuery 读取 XML 节点的好方法?有限循环!

发布于 2024-10-07 06:50:32 字数 967 浏览 0 评论 0原文

目前,feed xml 将返回 20 个项目(子项),每次我只想在单页中显示 10 个项目。 jQuery 的 .each 函数会循环整个文档,对吧?但我想让它只循环 10 个项目?我需要使用':eq()'吗?

注意:我需要将其用于移动设备环境。

<channel>​
 <title>​Property​</title>​
 <link>​</link>​
 <lastbuilddate>​Wed, 13 Oct 2010 23:50:51 GMT​</lastbuilddate>​
 <generator>​FeedCreator 1.8.0-dev ([email protected])​</generator>​
 <atom:link href=​"sample.com" rel=​"self" type=​"application/​rss+xml">​</atom:link>​
 <item>​
  <title>​sample title​</title>​
  <description>​
    #cdata-section
  </description>​
  <pubdate>Wed, 08 Dec 2010 23:04:25 GMT</pubdate>
 </item>​
 <item>... ... </item>
 <item>... ...</item>
 <item>... ... repeat 20 times </item>
<channel>​

Currently the feed xml will return 20 items (child), and each time I only want to display 10 item in single page. The .each function of jQuery will loop whole document right? but I want make it only loop 10 items? Do I need to use the ':eq()'?

Note: I need use this for mobile device environment.

<channel>​
 <title>​Property​</title>​
 <link>​</link>​
 <lastbuilddate>​Wed, 13 Oct 2010 23:50:51 GMT​</lastbuilddate>​
 <generator>​FeedCreator 1.8.0-dev ([email protected])​</generator>​
 <atom:link href=​"sample.com" rel=​"self" type=​"application/​rss+xml">​</atom:link>​
 <item>​
  <title>​sample title​</title>​
  <description>​
    #cdata-section
  </description>​
  <pubdate>Wed, 08 Dec 2010 23:04:25 GMT</pubdate>
 </item>​
 <item>... ... </item>
 <item>... ...</item>
 <item>... ... repeat 20 times </item>
<channel>​

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神爱温柔 2024-10-14 06:50:32

创建一个计数变量,

一旦达到 count=10,就通过执行 return false 来打破循环

doing a return /// 它应该打破循环

jsFiddle 示例在这里

http://jsfiddle.net/SxEVT/

Make a count variable ,

as soon as you reach count=10 break the loop by doing a return false

doing a return ///it should break the loop

jsFiddle example here

http://jsfiddle.net/SxEVT/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文