我制作了一个页面,允许2个玩家玩游戏,我使用2个iframe来加载2个文件.html的游戏,第一个iframe为玩家1,第二个iframe为玩家2.
但我有一个问题,我想玩玩家2我必须点击iframe 2,和玩家1一样;这意味着我一次只能玩一名球员。
所以你们对此有什么想法?有没有办法一次玩2个iframe? (我为每个玩家设置了不同的按钮)
这是我上面描述的屏幕
答案 0 :(得分:0)
您可以使用功能" parent"。
示例如下:
定义:
主页: demo.html
子页面: a.html &的 b.html 强>
demo.html
<!DOCTYPE html>
<html>
<body>
<iframe id="frame_A" src="a.html"></iframe>
<iframe id="frame_B" src="b.html"></iframe>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function callBFun() {
parent['frame_B'].changeHiValue(document.getElementById('user').value);
}
function callDirect() {
parent['frame_B'].document.getElementById('hi').innerHTML =
'Control:====>' + document.getElementById('user').value;
}
</script>
</head>
<body>
<h1 style="color: red;">This is a.html</h1>
<input type="text" id="user" size="8"><input type="button" onclick="callBFun()" value="call function from b.html"><input type="button" onclick="callDirect()" value="call dom from b.html">
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function changeHiValue(value) {
document.getElementById('hi').innerHTML = 'By calling:==>>==>>' + value;
}
</script>
</head>
<body>
<h1 style="color: blue;">It's the b</h1>
The value from a.html:
<label id="hi" style="color: red;"></label>
</body>
</html>
祝你好运;