on单击将参数添加到url
onClick add parameter to url
我正试图在我的网站上插入一个带有自定义缩略图的youtube视频。因此,我找到了我正在使用的这个代码。
<div onclick="this.nextElementSibling.style.display='block'; this.style.display='none'">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=myImage" style="cursor:pointer" />
</div>
<div style="display:none">
<iframe width="420" height="315" src="https://www.youtube.com/embed/TlMNLFiARBA?rel=0&autoplay=1" frameborder="0" allowfullscreen></iframe>
</div>
到目前为止,它是有效的,但自动播放使视频在封面图像后面播放。所以我尝试添加autoplay参数onClick,所以当封面隐藏时,它会变为true。
我试过使用
<div onclick="this.nextElementSibling.style.display='block';this.nextElementSibling.href + '?rel=0&autoplay=1'; this.style.display='none'">
但这不起作用。老实说,我没有JS背景,也不知道自己在做什么。有人能帮我吗?只需在单击时向给定的链接添加URL参数。
谢谢。
我认为你做事情的方式不对。
当您更改iframe的url时,iframe将重新加载,而不仅仅是开始播放。
试试这个:
<div onclick="this.nextElementSibling.style.display='block';this.nextElementSibling.children[0].src='https://www.youtube.com/embed/TlMNLFiARBA?rel=0&autoplay=1'; this.style.display='none'">
<img src="https://placeholdit.imgix.net/~text?txtsize=33&txt=myImage" style="cursor:pointer" />
</div>
<div style="display:none">
<iframe width="420" height="315" frameborder="0" allowfullscreen>
</iframe>
</div>
这将同时显示iframe和更改url。
相关文章:
- 如何在所有ajax调用中向URL添加参数
- 将URL添加到Javascript中
- 向 URL 添加额外的变量
- 浏览器向url添加一些数字
- Angular ui路由器向url添加哈希
- Highcharts将url添加到柱形图
- 在AngularJs中动态地将url添加到脚本标记中
- 将 URL 添加到浏览器后退按钮
- 使用 PhoneGap 在运行时将 URL 添加到 iPhone 中 cordova.plist 文件中的白名单中
- addClass 不起作用,尝试根据 URL 添加类
- 如何使用 Angular.js/Javascript 为 url 添加输入字段验证
- 如何阻止任何滑块向 URL 添加哈希标签
- 为与第一段匹配的任何 URL 添加活动类
- 使用 jsZip 将图像从 url 添加到 zip 文件
- 使用 JavaScript 或 jQuery 如何在页面加载后向 URL 添加参数
- jQuery:以最佳方式根据URL添加类
- 根据 URL 添加类 - 在主页上不起作用
- 替换并向 URL 添加 3 个不同的参数
- Div 叠加层淡入历史记录,并可使用哈希 URL 添加书签
- 如何将已上传的图像的 URL 添加到 Dropzone