JQuery如何使用选择器选择下一个id
html:
<div id="videos">
<a href="javascript:loadAndPlayVideo('QXoIMTjk9Xg')"><img src="http://i.ytimg.com/vi/QXoIMTjk9Xg/default.jpg" id="thumb_QXoIMTjk9Xg"></a>
<a href="javascript:loadAndPlayVideo('nWubfMkDfVs')"><img src="http://i.ytimg.com/vi/nWubfMkDfVs/default.jpg" id="thumb_nWubfMkDfVs"></a>
<a href="javascript:loadAndPlayVideo('S3WDKXq36WI')"><img src="http://i.ytimg.com/vi/S3WDKXq36WI/default.jpg" id="thumb_S3WDKXq36WI"></a>
<a href="javascript:loadAndPlayVideo('sGrfLQVVI8A')"><img src="http://i.ytimg.com/vi/sGrfLQVVI8A/default.jpg" id="thumb_sGrfLQVVI8A"></a>
</div>
问题: 我们有 ID“nWubfMkDfVs”,我们需要知道下一个 ID 才能获取播放列表功能。
注意:它没有thumb_,thumb_是因为我在另一个div中使用id nWubfMkDfVs并且想要避免重复的Id
问题1:如何制作一个为我们提供的选择器使用 nWubfMkDfVs 时 S3WDKXq36WI 作为响应?
问题2:如何制作一个选择器,在使用sGrfLQVVI8A时为我们提供QXoIMTjk9Xg作为响应?
我尝试了很多选择器,但都失败了,我很好奇你将如何解决这个问题!
The html:
<div id="videos">
<a href="javascript:loadAndPlayVideo('QXoIMTjk9Xg')"><img src="http://i.ytimg.com/vi/QXoIMTjk9Xg/default.jpg" id="thumb_QXoIMTjk9Xg"></a>
<a href="javascript:loadAndPlayVideo('nWubfMkDfVs')"><img src="http://i.ytimg.com/vi/nWubfMkDfVs/default.jpg" id="thumb_nWubfMkDfVs"></a>
<a href="javascript:loadAndPlayVideo('S3WDKXq36WI')"><img src="http://i.ytimg.com/vi/S3WDKXq36WI/default.jpg" id="thumb_S3WDKXq36WI"></a>
<a href="javascript:loadAndPlayVideo('sGrfLQVVI8A')"><img src="http://i.ytimg.com/vi/sGrfLQVVI8A/default.jpg" id="thumb_sGrfLQVVI8A"></a>
</div>
The problem:
We have the id 'nWubfMkDfVs' and we need to know the next ID in order to get playlist functionality.
Note: it's without the thumb_, the thumb_ is because I use the id nWubfMkDfVs in another div and want to avoid double Id's
Question 1: How to make a selector that gives us S3WDKXq36WI as response when using nWubfMkDfVs?
Question 2: How to make a selector that gives us QXoIMTjk9Xg as response when using sGrfLQVVI8A?
I tried a lot of selectors but they all failed, I'm very curious in how you will solve this problem!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为您引用的是嵌套在 a 内的 ID,所以您必须这样做:
注意,首先它选择父级,然后是下一个锚点,然后是 img 子级。
Because you are referencing an ID nested inside an a, you would have to do this:
Note, first it selects the parent, then the next anchor, then the img child.
试试这个(演示):
HTML
脚本
Try this (demo):
HTML
Script