首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

关于对opener使用appendChild的有关问题

2012-05-20 
关于对opener使用appendChild的问题有二个页面:页面f的内容为:HTML codebutton onclickwindow.open(t.

关于对opener使用appendChild的问题
有二个页面:页面f的内容为:

HTML code
<button onclick="window.open('t.html','','width=800,height=500')">页面</button><textarea id="myTextArea" cols="70" rows="20" name="content">网</textarea>


页面t的内容为

HTML code
<script>var alink=document.createElement("a");alink.href="www.baidu.com";alink.innerText="百度";var oTable = document.createElement("table");var oTBody = document.createElement("tbody");var oTR = document.createElement("tr");var oTD = document.createElement("td");oTD.appendChild(alink);oTR.appendChild(oTD);oTBody.appendChild(oTR);oTable.appendChild(oTBody);window.opener.document.getElementById("myTextArea").appendChild(oTable);</script>



通过f打开t后,window.opener.document.getElementById("myTextArea").appendChild(oTable);
这一句代码不能执行,请问是什么原因,要达到这样的效果应该怎么弄?

[解决办法]
#myTextArea是个多行文本输入框啊,怎么能嵌入别的对象。。你要做的是构造一个含有表格html代码的字符串,然后把这个字符串赋给#myTextArea对象的value属性:

JScript code
var html = '<table><tbody><tr><td><a href="http://www.google.com/">GOOGLE</a></td></tr></tbody></table>';window.opener.document.getElementById("myTextArea").value = html; 

热点排行