Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用按钮在iframe中打开文件_Javascript_Html_Button_Iframe_Onclick - Fatal编程技术网

Javascript 使用按钮在iframe中打开文件

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()

所以我有一个javascript文件,它可以工作,并由一个html按钮触发。问题是,我正在尝试这样做,当点击按钮时,游戏将出现在iframe窗口中。如何做到这一点

HTML:


如果您的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"; 
}