请问如何用js操作iframe嵌入的网页里的文本框
rt我在main.html里嵌入a.html,
a.html如图:
现在我要在main.html里面通过js获取a.html里面文本框里的文本,以及向文本框里写入文本,以及插入图片,该怎么做
a.html:
<html>
<head>
<title>Demo 2 : NicEdit Configuration</title>
</head>
<body>
<script src="../nicEdit.js" type="text/javascript"></script>
<script type="text/javascript">
bkLib.onDomLoaded(function() {
new nicEditor({maxHeight : 200}).panelInstance('area5');
});
</script>
<textarea style="height: 200px; width: 600px;" cols="50" id="area5"></textarea>
</div>
</div>
</body>
</html>
main.html:
--------------------编程问答-------------------- document.iframes[].contentwindow.document.getElementById().value --------------------编程问答-------------------- 要将Iframe 的句柄附给parent
<Iframe id="myFrame" name="myFrame" src="a.html" scrolling="yes" frameborder="1" style="position:absolute; width:600; height:300;background-color:transparent;border:3px;"/>
<script>
function getText() {
//在这里获取文本框里的内容
}
function writeText(str) {
//把内容写入文本框里面
}
function insert(imgUrl) {
//把图片插入到文本框里面
}
</script>
如,先在main.html中预定义一个js变量
<script>
var iframe_document;
</script>
<Iframe id="myFrame" name="myFrame" src="a.html" scrolling="yes" frameborder="1" style="position:absolute.....onload="setVal()"
...
<script>
function setVal()
{
var text=iframe_document.getElementById("area5");
alert(text.value);
text.value="修改内容了..";
}
</script>
a.html
最后一行加入
<script>
parent.iframe_document=document;
</script>
--------------------编程问答-------------------- 推荐楼主用jQuery
补充:.NET技术 , .NET Framework