0
    <script language="Javascript" type="text/javascript">
    function Next(){
        var randp = Math.floor(Math.random()*3);
        switch(randp){
            case 0:
                var websel = "http://w3schools.com";
                break;  
            case 1:
                var websel = "http://www.bbc.com/";
                break;
            case 2:
                var websel = "http://en.wikipedia.org/wiki/BBC";
                break;
            default:
                document.write("Error SWITCH(randp) " + randp + " ");
                break;
        }
    }
    </script>

    <iframe name="iframea" src="http://w3schools.com" seamless="seamless" scrolling="auto" height="560px" width="1080px" align="middle" scale="1.5"></iframe> 

 <input type="button" value="Next" onClick="Next()">

对不起,基本问题。我需要添加什么才能让下一个按钮打开一个链接(链接是来自函数的变量),目标是 iframe。谢谢

4

1 回答 1

2

您必须按以下方式更改 iframe 的 src:

        <script language="Javascript" type="text/javascript">
        function Next(){
            var randp = Math.floor(Math.random()*3);
            switch(randp){
                case 0:
                    var websel = "http://w3schools.com";
                    break;  
                case 1:
                    var websel = "http://www.bbc.com/";
                    break;
                case 2:
                    var websel = "http://en.wikipedia.org/wiki/BBC";
                    break;
                default:
                    document.write("Error SWITCH(randp) " + randp + " ");
                    break;
            }
            alert(websel);
            document.getElementById("iframea").src=websel;
        }
        </script>

        <iframe name="iframea" id="iframea" src="http://w3schools.com" seamless="seamless" scrolling="auto" height="560px" width="1080px" align="middle" scale="1.5"></iframe> 

     <input type="button" value="Next" onClick="Next()">

顺便说一句,你可能会在这个网站上看到这个问题是相似的。

于 2013-03-27T13:23:23.080 回答