javascript - 基于复选框在 iframe 上传递 URL

标签 javascript html iframe

抱歉,我不太擅长 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;
}

Here is the JSFiddle demo

关于javascript - 基于复选框在 iframe 上传递 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31647401/

相关文章:

javascript - FullCalendar React 中的 React Bootstrap Popover

javascript - react /Jest/ enzyme : How to test adding text to input and checking for that text?

javascript - D3.js词云不显示不报错

javascript - 如何删除 javascript src's if @media (min-width :xxx px) {

javascript - IE8 上出现类型不匹配错误?

javascript - 导入Vue破坏Vue

javascript - Angular 5 + Bootstrap 工具提示不起作用

javascript - 在 javascript 中提交表单后,IE 不会关闭窗口

javascript - 在页面中注入(inject)第 3 方 HTML(带有脚本)

python - Django Iframe Safari 修复