本文实例讲述了javascirpt实现2个iframe之间传值的方法。分享给大家供大家参考,具体如下:
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<table border="1" width="100%">
<tr>
<td width="100%"><iframe src="iframe1.html" name="aa"></iframe></td>
</tr>
<tr>
<td width="100%"><iframe src="iframe2.html" name="bb"></iframe></td>
</tr>
</table>
</body>
</html>
iframe1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
function aa() {
parent.frames["bb"].document.all["TextBox3"].value = document.getElementById("TextBox1").value;
parent.frames["bb"].document.all["TextBox4"].value = document.getElementById("TextBox2").value;
alert(parent.frames["bb"].document.all["TextBox3"].value);
alert(parent.frames["bb"].document.all["TextBox4"].value);
}
</script>
</head>
<body>
<form id="a">
<input id="TextBox1" type="text" id="TextBox1" value="1">
<input id="TextBox2" type="text " id="TextBox2" value="2">
<input id="T" type="button" value="33333" onclick="aa()">
</form>
</body>
</html>
iframe2.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form id="b">
<input id="TextBox3" type="text" id="TextBox1" value="1231111">
<input id="TextBox4" type="text" id="TextBox2" value="123">
</form>
</body>
</html>