动态 vimeo 嵌入选项
我正在尝试添加带有选项(颜色等)的 Vimeo 嵌入。然而,如果 iframe 是使用 jQuery 或 DOM 创建的,Vimeo 似乎无法识别这些选项:
var fail = $('<iframe>', {
src: 'http://player.vimeo.com/video/36825140?title=0&byline=0&portrait=0&color=a4a9ab'
});
但是,如果我使用innerHTML,它就可以工作(它也可以使用纯 HTML 工作)。
var ok = $('<div>').html('<iframe src="http://player.vimeo.com/video/36825140?title=0&byline=0&portrait=0&color=a4a9ab"></iframe>');
测试小提琴: http://jsfiddle.net/nhkr5/
我真的很想使用 DOM 工具来完成该任务,这样我就可以引用 iframe 元素并摆脱额外的包装器。
还有另一种“正确”的方法吗?
I’m trying to add Vimeo embeds with options (colors, etc). However, it seems that Vimeo doesn’t recognize the options if the iframe is created using jQuery or DOM:
var fail = $('<iframe>', {
src: 'http://player.vimeo.com/video/36825140?title=0&byline=0&portrait=0&color=a4a9ab'
});
But, if I use innerHTML, it works (it also works using plain HTML).
var ok = $('<div>').html('<iframe src="http://player.vimeo.com/video/36825140?title=0&byline=0&portrait=0&color=a4a9ab"></iframe>');
Test fiddle: http://jsfiddle.net/nhkr5/
I would really like to use DOM tools for the task, so I can reference the iframe element and get rid of the extra wrapper.
Is there another "correct" way of doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您检查动态创建的 iframe,您会发现
&
实体未解析,因此src 中没有
,但字面意思&
&
http://jsfiddle.net/ nhkr5/1/
If you inspect the dynamically created iframe, you will discover that the
&
entities are not resolved, so you don't have&
in thesrc
, but literal&
http://jsfiddle.net/nhkr5/1/