通过 jQuery 读取 XML 节点的好方法?有限循环!
目前,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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个计数变量,
一旦达到 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 loopjsFiddle example here
http://jsfiddle.net/SxEVT/