gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 00:02:41 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com