jQuery - 通过唯一 ID 对多个对象迭代 API 命令?
我在一个页面上有一堆 vimeos,我想让它们全部静音,因为它们将同时播放。
我只在一个 vimeo 上运行。因为它需要每个 vimeo 的唯一 ID。 但我对对视频做不同的事情不感兴趣。我只想给他们一条规则,显然不必每次上传新的 vimeo 时都写出来。
var iframe = document.getElementById("player_1");
iframe.api("api_setVolume", 50);
我尝试让所有 vimeo 的 ID =player_1,但这不起作用。 由于某种原因,JS 中没有 getElementByClass,应该没有吧?对于这样的事情会有用。
任何帮助将不胜感激。谢谢。
这是测试页面
I have a stack of vimeos on a page, I want to make them all mute though as they will be playing simultaneously.
I've got it working on only one vimeo. As it needs the unique ID for each vimeo.
But I'm not interested in doing different things to the videos. I just want to give them one rule, and obviously not have to write it out each time I upload a new vimeo.
var iframe = document.getElementById("player_1");
iframe.api("api_setVolume", 50);
I tried making all the vimeo's ID = player_1, but that doesn't work.
For some reason there's no getElementByClass in JS, there should be no? It'd be useful for things like this.
Any help would be greatly appreciated. Thanks.
Here's the testpage
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于它被标记为 jQuery,因此我将为您提供一个应该适用于该问题的解决方案,尽管我还没有尝试过使用 iframe 类。
将
class="vimeo"
添加到 iframe。使用以下代码迭代它们:each
将迭代与选择器匹配的所有元素(在本例中为vimeo
)。编辑
由于 jQuery 似乎不喜欢搞乱 iframe,因此有一种更加编程的方式来完成已经为您工作的操作:
现在的技巧是确定
player_count
应该是什么。Since this is tagged jQuery, I'll give you a solution that should work for that, though I haven't tried messing with iframe classes.
Add
class="vimeo"
to the iframes. Iterate through them with the following:each
will iterate through all the elements that are matched by the selector (in this case,vimeo
).EDIT
Since jQuery doesn't seem to like messing with iframes, there's a more programmatic way of doing what's already working for you:
The trick now is determining what
player_count
should be.jQuery 将允许您使用以下语法按类选择一组元素: $(".myClass")
http: //api.jquery.com/class-selector/
jQuery will let you select a set of elements by class with the syntax: $(".myClass")
http://api.jquery.com/class-selector/