Javascript 使用按钮在iframe中打开文件
所以我有一个javascript文件,它可以工作,并由一个html按钮触发。问题是,我正在尝试这样做,当点击按钮时,游戏将出现在iframe窗口中。如何做到这一点 HTML:Javascript 使用按钮在iframe中打开文件,javascript,html,button,iframe,onclick,Javascript,Html,Button,Iframe,Onclick,所以我有一个javascript文件,它可以工作,并由一个html按钮触发。问题是,我正在尝试这样做,当点击按钮时,游戏将出现在iframe窗口中。如何做到这一点 HTML: 如果您的html代码(与'和“相关)有问题,请将按钮代码更改为: <input id="clickThis" type="button" value="JavaScript Game" onclick="this.disabled='disabled'; target='jsgame'; thatFunction()
如果您的html代码(与
'
和“
相关)有问题,请将按钮代码更改为:
<input id="clickThis" type="button" value="JavaScript Game" onclick="this.disabled='disabled'; target='jsgame'; thatFunction();" />
或者这段代码,因为我注意到您正在将iframe的id分配给javascript变量target
<script type="text/javascript">
function thatFunction()
{
document.getElementById(target).setAttribute("src","frame.php");
}
</script>
函数that function()
{
getElementById(target.setAttribute(“src”、“frame.php”);
}
这确实是一个简单的javascript函数
function openGame(){
document.getElementById("jsgame").src="http://www.example.com";
}
拨弄
<script type="text/javascript">
function thatFunction()
{
document.getElementById(target).setAttribute("src","frame.php");
}
</script>
function openGame(){
document.getElementById("jsgame").src="http://www.example.com";
}