发表于:2008-03-08 16:32:20 楼主
HTML code
<html>
<head>
<script type="text/javascript"> show_on = function(){
var myinput = document.getElementById("myinput");
var ifrm = document.getElementById("hdnfrm");
ifrm = ifrm.contentWindow.document;
var ifrm_body = ifrm.body;
var ofile = ifrm.createElement("input");
ifrm_body.appendChild(ofile); }window.onload = show_on;
</script>
</head>
<body>
<span id="myinput"><iframe id="hdnfrm" style="width:283px;height:230px;" scrolling="no" frameborder="1" ></iframe></span>
</body>
</html>以上代码无问题,能够在firefox页面里面的iframe里正常添加个input HTML code
<html>
<head>
<script type="text/javascript"> show_on = function(){
var myinput = document.getElementById("myinput");
var ifrm = document.createElement("iframe");
ifrm.setAttribute("style","width:283px;height:230px;");
ifrm.setAttribute("scrolling","no");
ifrm.setAttribute("frameborder","1");
myinput.appendChild(ifrm);
ifrm = ifrm.contentWindow.document;
var ifrm_body = ifrm.body;
alert(ifrm);//看看是否为对象
var ofile = ifrm.createElement("input");
t=setTimeout(function(){ifrm_body.appendChild(ofile);},2000)//试试过两秒看行不行.
}window.onload = show_on;
</script>
</head>
<body>
<span id="myinput"></span>
</body>
</html>
HTML code
<html>
<head>
<script type="text/javascript"> show_on = function(){
var myinput = document.getElementById("myinput");
var ifrm = document.getElementById("hdnfrm");
ifrm = ifrm.contentWindow.document;
var ifrm_body = ifrm.body;
var ofile = ifrm.createElement("input");
ifrm_body.appendChild(ofile); }window.onload = show_on;
</script>
</head>
<body>
<span id="myinput"><iframe id="hdnfrm" style="width:283px;height:230px;" scrolling="no" frameborder="1" ></iframe></span>
</body>
</html>以上代码无问题,能够在firefox页面里面的iframe里正常添加个input HTML code
<html>
<head>
<script type="text/javascript"> show_on = function(){
var myinput = document.getElementById("myinput");
var ifrm = document.createElement("iframe");
ifrm.setAttribute("style","width:283px;height:230px;");
ifrm.setAttribute("scrolling","no");
ifrm.setAttribute("frameborder","1");
myinput.appendChild(ifrm);
ifrm = ifrm.contentWindow.document;
var ifrm_body = ifrm.body;
alert(ifrm);//看看是否为对象
var ofile = ifrm.createElement("input");
t=setTimeout(function(){ifrm_body.appendChild(ofile);},2000)//试试过两秒看行不行.
}window.onload = show_on;
</script>
</head>
<body>
<span id="myinput"></span>
</body>
</html>
HTML code
<html>
<head>
<script type="text/javascript"> show_on = function(){
var myinput = document.getElementById("myinput");
var ifrm = document.createElement("iframe");
ifrm.setAttribute("style","width:283px;height:230px;");
ifrm.setAttribute("scrolling","no");
ifrm.setAttribute("frameborder","1");
myinput.appendChild(ifrm);
ifrm = ifrm.contentWindow.document;
var ifrm_body = ifrm.body;
alert(ifrm);//看看是否为对象
var ofile = ifrm.createElement("input");
t=setTimeout(function(){ifrm_body.appendChild(ofile);},2000)//试试过两秒看行不行.
} window.onload = show_on;
</script>
</head>
<body>
<span id="myinput"> </span>
</body>
</html> 经过测试,它肯定是对象,经过2秒后再试也不行
对啊!我用innerHTML是能看到已经添加成功的!!
就是没显示..难道是BUG吗?
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<select name="listbox1" size="4" multiple>
<option value="sdgs">sdg</option>
<option value="sg">sdg</option>
<option value="sdg">sdg</option>
</select>
</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--
var frm = document.createElement("iframe");
document.body.appendChild(frm);
var ifram = document.frames[0];
ifram.document.write("这是动态生成的<br>");
frm.document.write("这是动态生成的");
var listbox = document.all("listbox1")
for(var i=0;i<listbox.length;i++)
{
ifram.document.write(listbox[i].value + "<br>");
}
//-->
</SCRIPT>这个例子你能看明白吗
谢谢你的回答,但是你的代码一样..在IE中正常..在FF中依然没反应...
<html>
<head>
<script type="text/javascript"> show_on = function(){
myinput = document.getElementById("myinput");
ifrm = document.createElement("iframe");
ifrm.setAttribute("style","width:283px;height:230px;");
ifrm.setAttribute("scrolling","no");
myinput.appendChild(ifrm);
ifrm_d = ifrm.contentWindow.document;
var ifrm_body = ifrm_d.body;
var ofile = ifrm_d.createElement("input");
ofile.value="asdf";
ifrm_body.appendChild(ofile);
setTimeout(tt,"20ms"); }
function tt(){
ifrm_d = ifrm.contentWindow.document;
var ifrm_body = ifrm_d.body;
var ofile = ifrm_d.createElement("input");
ifrm_body.appendChild(ofile);
}window.onload = show_on;
</script>
</head>
<body>
<div id="myinput"></span>
<input type="button" id="sd" onClick="tt()">
</body>
</html>这是可行的。
曾经在FF的官方网站看的某篇E文文章好像有说这样可以解决一些BUG..
晕..奇怪...不过谢谢
yangbo99
哦,原来是这样啊,谢谢!
不过,在IE(6.0)下好像又通不过了,
var ifrm_body = ifrm_d.body;
IE不认识body属性
…………
var ifrm_body = ifrm_d;
测试通过,不知对不对