iframe 内容不显示
Iframe content not displaying
我正在尝试创建一个 iframe,其中的内容会根据按钮点击而改变。但是 iframe 没有显示任何内容。谁能看看我的代码并解释原因。
<script>
int i = 0;
var array= ["news1.html","news2.html","news3.html"];
function setURL(){
if (i<2) {
i = i+1;
}
else{
i=0;
};
document.getElementById("iframe").src = array[i];
}
</script>
<iframe id="iframe" style="float:right;" width="770" height="360"></iframe>
<button type="button" onclick="setURL()" style="float:right;"> Next </button>
我知道这不是世界上最好的代码,但据我所知它应该可以工作,所以我希望能得到帮助?
更改您的变量声明:
int i = 0;
至:
var i = 0;
我更改后一切正常。
我正在尝试创建一个 iframe,其中的内容会根据按钮点击而改变。但是 iframe 没有显示任何内容。谁能看看我的代码并解释原因。
<script>
int i = 0;
var array= ["news1.html","news2.html","news3.html"];
function setURL(){
if (i<2) {
i = i+1;
}
else{
i=0;
};
document.getElementById("iframe").src = array[i];
}
</script>
<iframe id="iframe" style="float:right;" width="770" height="360"></iframe>
<button type="button" onclick="setURL()" style="float:right;"> Next </button>
我知道这不是世界上最好的代码,但据我所知它应该可以工作,所以我希望能得到帮助?
更改您的变量声明:
int i = 0;
至:
var i = 0;
我更改后一切正常。