如何用js赋值给网页iframe里的网页的控件例如text的值?
举个例子:网页a.html<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.o...
举个例子 :
网页 a.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
</head>
<body>
<iframe id="a" name="a" src="b.htm" style="width: 712px; height: 419px"> </iframe>
<script type="text/javascript">
var aaa=document.getElementById("a");
var bbb=aaa.contentWindow.document.getElementById("Text1");
bbb.value="你好!";
</script>
</body>
</html>
网页 b.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
</head>
<body>
<input id="Text1" name="Text1" style="width: 318px" type="text" />
</body>
</html>
调试提示错误
错误: 'bbb' 为空或不是对象
哪位朋友帮我看看啊 ,谢谢了 展开
网页 a.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
</head>
<body>
<iframe id="a" name="a" src="b.htm" style="width: 712px; height: 419px"> </iframe>
<script type="text/javascript">
var aaa=document.getElementById("a");
var bbb=aaa.contentWindow.document.getElementById("Text1");
bbb.value="你好!";
</script>
</body>
</html>
网页 b.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
</head>
<body>
<input id="Text1" name="Text1" style="width: 318px" type="text" />
</body>
</html>
调试提示错误
错误: 'bbb' 为空或不是对象
哪位朋友帮我看看啊 ,谢谢了 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询