Change iframe src without page update(在不更新页面的情况下更改iframe src)
本文介绍了在不更新页面的情况下更改iframe src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
查看我的HTML代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">Launch demo modal</button>
<div id="myModal" class="modal fade" role="dialog" tabindex='-1'>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<p class="modal-title">SECRETS OF SUPERIOR CUSTOMER SERVICE (July 22, 2016)</p>
</div>
<div class="modal-body">
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="http://chishare.cc/embed/2107778410/" allowfullscreen="" width="640" height="360" frameborder="0"></iframe>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
</div>
</div>
</div>
我的主要问题是:如何在不刷新页面的情况下更改此iframe src视频?
如下所示:
<button type="button" onclick="src1()">Change to video 1</button>
<button type="button" onclick="src2()">Change to video 2</button>
<button type="button" onclick="src3()">Change to video 3</button>
<button type="button" onclick="src4()">Change to video 4</button>
及其各自的功能:
function src1(){
-- Change the iframe src link of myModal
}
function src2(){
-- Change the iframe src link of myModal
}
...
你能帮我吗? 谢谢
推荐答案
第1步:使用iFrame.
<iframe id="FrameId"></iframe>
第2步:更新按钮.
<button type="button" onclick="ChangeSource(1);">Change to video 1</button>
第3步:包含此函数.
function ChangeSource(Button){
if(Button==1){FrameId.src='URL 1';} else
if(Button==2){FrameId.src='URL 2';} else
if(Button==3){FrameId.src='URL 3';} else
if(Button==4){FrameId.src='URL 4';}
}
这篇关于在不更新页面的情况下更改iframe src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
编程基础网
本文标题为:在不更新页面的情况下更改iframe src
基础教程推荐
猜你喜欢
- 在 Javascript 中使用 Fetch API 上传文件并显示进度 2022-01-01
- 从快速中间件中排除路由 2022-01-01
- 使用 jQuery 在悬停时交换 DIV 类 2022-01-01
- 即使每次插入第一个输入的值不同,第二个输入仍显示相同的输入值 2022-01-01
- 带角度的选项卡:仅使用 $http 在单击时加载选项卡 2022-01-01
- 最佳动态 JavaScript/JQuery 网格 2022-01-01
- HTML5 画布调整为父级 2022-01-01
- CORS:当凭据标志为真时,无法在 Access-Control-Allow-Origin 中使用通配符 2022-01-01
- 当木偶师打开Chrome时,不能使用Chrome扩展 2022-01-01
- 逻辑运算符 ||在 javascript 中,0 代表 Boolean false? 2022-01-01
