基于复选框在iframe上传递URL
Pass URL on an iframe based on checkbox
对不起,我很不擅长JavaScript,我刚刚开始学习它。我有这样一个场景:我想传递一个URL到我的iframe,那么我该如何创建一个脚本呢?
<script>
/* Pseudocode
if var variable1 is true then pass url to iframe with variable1 as value
else if var variable2 is true then pass url to iframe with variable2 as value
else let the default url
*/
</script>
Hope someone can know this.
Thank you!
<input type="checkbox" name="vehicle" value="(variable1)">
<input type="checkbox" name="vehicle" value="(variable2)">
<iframe id="javascriptID" src="(variable(1or2)">
</iframe>
你可以使用单选按钮,然后这样做:
HTTPSNow
<input type="radio" name="vehicle" value="https://www.httpsnow.org/" onclick="setURL(this.value)"/>
<br/>
Example.com
<input type="radio" name="vehicle" value="https://www.example.com/" onclick="setURL(this.value)"/>
<br/>
<iframe id="javascriptID" src="" width="500px" height="500px">
</iframe>
function setURL(thelink){
javascriptID.src=thelink;
}
这里是JSFiddle演示
如果你仍然想使用复选框,你可以使用这个- jQuery:
$("input[name=vehicle]").change(function(){
if($(this).is(":checked")){
// do some thing here
}
})
但我认为这不是一个好主意,因为复选框不是唯一的
相关文章:
- 如何使用javascript/jquery获取iframe的URL的锚点属性
- 重定向iFrame中的父URL
- iFrame url更改时执行函数
- 在iframe中加载url并添加一个类
- 如何使用iFrame在不同的域中匹配URL
- 编码url并显示在iframe中
- 是否可以添加<脚本>添加'_someTag'到iFrame中的URL
- 如何调整跨域url中iframe的大小
- 一些url没有在iframe中打开
- 我想从iframe获取url
- 嵌入iframe URL以在wordpress中包含当前用户id
- 绕过同源策略,从跨域iframe中获取页面的顶部URL
- iframe url在浏览器上打开
- 如何检查 iframe 中的锚标记是否包含 URL
- IFrame 从不同域上的父 url 获取参数
- 将当前页面 URL 传递给 iframe 地址
- 如何使用 React 替换 iframe 的 URL
- 由 URL 触发的来自 iFrame 的 JavaScript 重定向
- 为什么当我尝试为iframe-src属性构建URL时,AngularJS会抛出错误
- 只允许表单提交,如果从某个URL?(iframe Laravel)