簡體   English   中英

用於更改iFrame的單選按鈕不起作用

[英]Radio buttons to change iFrame not working

我不太確定自己做對了,我可能使用了錯誤的函數,但是:

<script>
    function go(loc){
        document.getElementById('iframe').src = loc;
    }
</script>

我想將登錄詳細信息容器中的iframe更改為通過單選按鈕選擇的任何頁面(還有如何使第一個單選按鈕自動選擇?)

<div class="logins_details_container"><!--The top container-->
    <iframe id="iframe" src="home_schedule_iframe.php" width="100%" height="100%"></iframe>
</div>  
<div class="iframe_container">
    <form>
        <input type="radio" name="iframe" value="type" onselect = "go('maths_iframe.php')"/>Maths<br>
        <input type="radio" name="iframe" value="type" onselect = "go('ict_iframe.php')"/>ICT
    </form>
</div>

盡管onSelect您只需要使用onClick函數。

所以代碼會像這樣

的JavaScript

<script>
    function go(loc){
      console.log(loc);
        document.getElementById('iframe').src = loc; 
    }
</script>

的HTML

<div class="logins_details_container"><!--The top container-->
    <iframe id="iframe" src="home_schedule_iframe.php" width="100%" height="100%"></iframe>
</div>  
<div class="iframe_container">
    <form>
        <input type="radio" name="iframe" value="type" onClick= "go('maths_iframe.php')"/>Maths<br>
        <input type="radio" name="iframe" value="type" onClick = "go('ict_iframe.php')"/>ICT
    </form>
</div>

這里是小提琴運行代碼(這不會是能夠加載maths_iframe.phpict_iframe.php明顯,因為它們不存在於服務器上)。

<script>
    function go(loc){
        alert(loc);
        document.getElementById('myframe').src = loc;
    }
</script>

<div class="logins_details_container"><!--The top container-->
    <iframe id="myframe" src="home_schedule_iframe.php" width="100%" height="100%"></iframe>
</div>  
<div class="iframe_container">
    <form>
        <input type="radio" name="iframe" value="type" onclick = "go('maths_iframe.php')"/>Maths<br>
        <input type="radio" name="iframe" value="type" onclick = "go('ict_iframe.php')"/>ICT
    </form>
</div>

小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM