关于iframe的问题 比如我现在有一JSP页面,页面中有两个iframe ID分别是 if1 if2其中在if1 中有一文本框,ID="tx"在if2 中有一按钮,请问,如果点周IF2中的按钮时,改变IF1中文本框的值 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if1 :var if2;if(frames.document.frames){ if2=top.frames.document.frames("if2");}else{if2 = top.document.getElementById('if2').contentWindow;}if2.document.getElementById('tx').value=""; 具体参考...主文件<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title></head><style type="text/css">*{font-family:verdana; font-size:12px;}div{border:1px solid red; padding:2px;}</style><script type="text/javascript">function $(id){return "string" == typeof(id) ? document.getElementById(id) : id ;}</script><body><p>在 IFrame2 页面修改 IFrame1 页面的输入框值</p>IFrame1:<br><iframe id="if1" name="if1" src="if1.htm" height="200" width="400"></iframe><hr size="1">IFrame2:<br><iframe id="if2" name="if2" src="if2.htm" height="200" width="400"></iframe></body></html>if1.htm<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title></head><body><input type="text" id="tx" name="tx" value="input box" size="30"></body></html>if2.htm<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title></head><script type="text/javascript">function $(id){return "string" == typeof(id) ? document.getElementById(id) : id ;}function chanValue(){var s=$("input2").value;var ow=parent.document.getElementById("if1").contentWindow;var otx=ow.document.getElementById("tx");otx.value=s;}</script><body><input name="input2" type="text" id="input2" value="Test new value from iframe 2" size="30"><br><input type="button" id="btn01" name="btn01" value="TEST" onClick="javascript:chanValue();"></body></html> 求助...对象set get方法出现奇怪现象 如何让超链接的title不消失? 事件 判断 select项的变化 这个js判断怎么理解? javascript minibrowser? JS导航条 关于form中的元素数组问题 脚本能否捕获鼠标滚轮事件 如何判断是否是0到1之间的2位小数 两个js有冲突,放在一起就有一个功能不能实现 window.onload 是不是也等iframe窗口的内容也载入完毕才 执行事件? 导入txt或excel文件 到 文本区里
var if2;
if(frames.document.frames){
if2=top.frames.document.frames("if2");
}else{
if2 = top.document.getElementById('if2').contentWindow;
}if2.document.getElementById('tx').value="";
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<style type="text/css">
*{font-family:verdana; font-size:12px;}
div{border:1px solid red; padding:2px;}
</style>
<script type="text/javascript">
function $(id){
return "string" == typeof(id) ? document.getElementById(id) : id ;
}</script>
<body>
<p>
在 IFrame2 页面修改 IFrame1 页面的输入框值
</p>
IFrame1:<br>
<iframe id="if1" name="if1" src="if1.htm" height="200" width="400"></iframe>
<hr size="1">
IFrame2:<br>
<iframe id="if2" name="if2" src="if2.htm" height="200" width="400"></iframe>
</body>
</html>if1.htm<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<input type="text" id="tx" name="tx" value="input box" size="30">
</body>
</html>
if2.htm<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<script type="text/javascript">
function $(id){
return "string" == typeof(id) ? document.getElementById(id) : id ;
}function chanValue(){
var s=$("input2").value;
var ow=parent.document.getElementById("if1").contentWindow;
var otx=ow.document.getElementById("tx");
otx.value=s;
}</script>
<body>
<input name="input2" type="text" id="input2" value="Test new value from iframe 2" size="30">
<br>
<input type="button" id="btn01" name="btn01" value="TEST" onClick="javascript:chanValue();">
</body>
</html>