如何象iframe中插入一段已经存的html? iframe.document.location.reload;iframe.document.write(......); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 emu(ston) 你好。谢谢你回答。主 题: 如何象iframe中插入一段已经存的html? 作 者: icerose (冰玫瑰) 我不知是否因为的水平太差没看明白你的程序,或者是我问题表达的不清。我是意思是在一个window中有一个iframe,此时为空。在iframe之外和两个tabel两个button.当点击第一个button时,在先清空iframe的内容,然后将第一个table插入iframe中当点击第二个button时,在先清空iframe的内容,然后将第二个table插入iframe中iframe.document.write(......);我想参数应是一段超文本吧。我想问是不可以传入表格的id之类东西。可以一下子写入一大段内容。谢谢。 呵呵,iframeName.innerHTML=" " 表格啊,呵呵,自己做啊"<table></table>................"多运用一下JAVASCRIPT设置一下就可以了 ifram 有 innerHTML 属性吗?我的办法是:在 iframe 的页面中定义一个 div,比如叫 divX;或者在 window.onload 时用 document.write 往 iframe 中写一个 div;在主窗口中定义两个 div,div1 包含 table1;div2 包含 table2;button1.onclick: iframe1.divX.innerHTML = div1.innerHTMLbutton2.onclick: ... 这么干 :<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title></title></head><body><iframe src="Noname2.html" id=test></iframe><BR><button onclick="show1()">test</button> <button onclick="show2()">test</button><SCRIPT LANGUAGE="JavaScript"><!--function show1(){test.document.location.reload();test.document.write("<TABLE>");test.document.write("<TR>");test.document.write(" <TD>abc</TD>");test.document.write(" <TD>dev</TD>");test.document.write("</TR>");test.document.write("<TR>");test.document.write(" <TD>ghi</TD>");test.document.write(" <TD>jkl</TD>");test.document.write("</TR>");test.document.write("</TABLE>");}function show2(){test.document.location.reload();test.document.write("<TABLE>");test.document.write("<TR>");test.document.write(" <TD>123</TD>");test.document.write(" <TD>456</TD>");test.document.write("</TR>");test.document.write("<TR>");test.document.write(" <TD>789</TD>");test.document.write(" <TD>000</TD>");test.document.write("</TR>");test.document.write("</TABLE>");}//--></SCRIPT></body></html> 要是用innerHTML可以这么写:<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title></title></head><body><iframe src="Noname2.html" id=test></iframe><BR><button onclick="show1()">test1</button> <button onclick="show2()">test2</button><SCRIPT LANGUAGE="JavaScript"><!--function show1(){test.document.body.innerHTML = "";test.document.write("<TABLE>");test.document.write("<TR>");test.document.write(" <TD>abc</TD>");test.document.write(" <TD>dev</TD>");test.document.write("</TR>");test.document.write("<TR>");test.document.write(" <TD>ghi</TD>");test.document.write(" <TD>jkl</TD>");test.document.write("</TR>");test.document.write("</TABLE>");}function show2(){test.document.body.innerHTML = "";test.document.write("<TABLE>");test.document.write("<TR>");test.document.write(" <TD>123</TD>");test.document.write(" <TD>456</TD>");test.document.write("</TR>");test.document.write("<TR>");test.document.write(" <TD>789</TD>");test.document.write(" <TD>000</TD>");test.document.write("</TR>");test.document.write("</TABLE>");}//--></SCRIPT></body></html>但是页面就不能有默认的内容了 要是table已经存在的话可以这么写:<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title></title></head><body><iframe src="Noname2.html" id=test></iframe><BR><TABLE><TR> <TD>abc</TD> <TD>def</TD></TR><TR> <TD>ghi</TD> <TD>jkl</TD></TR></TABLE><BR><BR><TABLE><TR> <TD>123</TD> <TD>456</TD></TR><TR> <TD>789</TD> <TD>000</TD></TR></TABLE><BR><BR><button onclick="show1()">test1</button> <button onclick="show2()">test2</button><SCRIPT LANGUAGE="JavaScript"><!--function show1(){//把当前页面第一个表格写到iframe里面test.document.body.innerHTML = document.all.tags("table")[0].outerHTML}function show2(){//把当前页面第二个表格写到iframe里面test.document.body.innerHTML = document.all.tags("table")[1].outerHTML}//--></SCRIPT></body></html>当然也可以给每个table对象一个id号来引用而不是通过all来引用:<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title></title></head><body><iframe src="Noname2.html" id=test></iframe><BR><TABLE id=table1><TR> <TD>abc</TD> <TD>def</TD></TR><TR> <TD>ghi</TD> <TD>jkl</TD></TR></TABLE><BR><BR><TABLE id=table2><TR> <TD>123</TD> <TD>456</TD></TR><TR> <TD>789</TD> <TD>000</TD></TR></TABLE><BR><BR><button onclick="show1()">test1</button> <button onclick="show2()">test2</button><SCRIPT LANGUAGE="JavaScript"><!--function show1(){//把当前页面第一个表格写到iframe里面test.document.body.innerHTML = table1.outerHTML}function show2(){//把当前页面第二个表格写到iframe里面test.document.body.innerHTML = table2.outerHTML}//--></SCRIPT></body></html> 谢谢大家的热情帮助。andysern(风亦),呵,呵.如果我能提前知道表格是什么样子的,我还用通过函数动态的插入吗?直接写入不就行了?:-)lonelyghost() 你的方法,让我想到如何在同一网页内插入的东东的办法了,谢谢emu(ston) :太谢谢了。 json问题:在页面不显示 怎么样把这小段代码写成一个函数? [ext问题]请教如何提高ext的性能 自定义右健菜单,在图片上点击右健,弹出自定义菜单,谢谢!在线等! 怎样修改这个button的值呢,他本身写在了js中。 JS随机函数random控制显示问题 我叫什么名字 有没有不用frame分框的树型菜单??? 请问大家有没有到一定日期从右下角出来个窗口浮上来提示的代码? 好想研究一下怎样强制终止javascript的执行? 为何我使用 templateprinter 会有 permission denied 怎样解决空格问题?
你好。
谢谢你回答。
主 题: 如何象iframe中插入一段已经存的html?
作 者: icerose (冰玫瑰) 我不知是否因为的水平太差没看明白你的程序,或者是我问题表达的不清。
我是意思是在一个window中有一个iframe,此时为空。在iframe之外和两个tabel两个button.
当点击第一个button时,在先清空iframe的内容,然后将第一个table插入iframe中
当点击第二个button时,在先清空iframe的内容,然后将第二个table插入iframe中iframe.document.write(......);我想参数应是一段超文本吧。我想问是不可以传入
表格的id之类东西。可以一下子写入一大段内容。谢谢。
表格啊,呵呵,自己做啊"<table></table>................"
多运用一下JAVASCRIPT设置一下就可以了
在 iframe 的页面中定义一个 div,比如叫 divX;或者在 window.onload 时用 document.write 往 iframe 中写一个 div;
在主窗口中定义两个 div,div1 包含 table1;div2 包含 table2;
button1.onclick: iframe1.divX.innerHTML = div1.innerHTML
button2.onclick: ...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
<iframe src="Noname2.html" id=test>
</iframe>
<BR>
<button onclick="show1()">test</button>
<button onclick="show2()">test</button>
<SCRIPT LANGUAGE="JavaScript">
<!--
function show1()
{
test.document.location.reload();
test.document.write("<TABLE>");
test.document.write("<TR>");
test.document.write(" <TD>abc</TD>");
test.document.write(" <TD>dev</TD>");
test.document.write("</TR>");
test.document.write("<TR>");
test.document.write(" <TD>ghi</TD>");
test.document.write(" <TD>jkl</TD>");
test.document.write("</TR>");
test.document.write("</TABLE>");}
function show2()
{
test.document.location.reload();
test.document.write("<TABLE>");
test.document.write("<TR>");
test.document.write(" <TD>123</TD>");
test.document.write(" <TD>456</TD>");
test.document.write("</TR>");
test.document.write("<TR>");
test.document.write(" <TD>789</TD>");
test.document.write(" <TD>000</TD>");
test.document.write("</TR>");
test.document.write("</TABLE>");}
//-->
</SCRIPT>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
<iframe src="Noname2.html" id=test>
</iframe>
<BR>
<button onclick="show1()">test1</button>
<button onclick="show2()">test2</button>
<SCRIPT LANGUAGE="JavaScript">
<!--
function show1()
{
test.document.body.innerHTML = "";
test.document.write("<TABLE>");
test.document.write("<TR>");
test.document.write(" <TD>abc</TD>");
test.document.write(" <TD>dev</TD>");
test.document.write("</TR>");
test.document.write("<TR>");
test.document.write(" <TD>ghi</TD>");
test.document.write(" <TD>jkl</TD>");
test.document.write("</TR>");
test.document.write("</TABLE>");}
function show2()
{
test.document.body.innerHTML = "";
test.document.write("<TABLE>");
test.document.write("<TR>");
test.document.write(" <TD>123</TD>");
test.document.write(" <TD>456</TD>");
test.document.write("</TR>");
test.document.write("<TR>");
test.document.write(" <TD>789</TD>");
test.document.write(" <TD>000</TD>");
test.document.write("</TR>");
test.document.write("</TABLE>");}
//-->
</SCRIPT>
</body>
</html>
但是页面就不能有默认的内容了
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
<iframe src="Noname2.html" id=test>
</iframe>
<BR>
<TABLE>
<TR>
<TD>abc</TD>
<TD>def</TD>
</TR>
<TR>
<TD>ghi</TD>
<TD>jkl</TD>
</TR>
</TABLE>
<BR><BR>
<TABLE>
<TR>
<TD>123</TD>
<TD>456</TD>
</TR>
<TR>
<TD>789</TD>
<TD>000</TD>
</TR>
</TABLE>
<BR>
<BR>
<button onclick="show1()">test1</button>
<button onclick="show2()">test2</button>
<SCRIPT LANGUAGE="JavaScript">
<!--
function show1()
{
//把当前页面第一个表格写到iframe里面
test.document.body.innerHTML = document.all.tags("table")[0].outerHTML
}
function show2()
{
//把当前页面第二个表格写到iframe里面
test.document.body.innerHTML = document.all.tags("table")[1].outerHTML
}
//-->
</SCRIPT>
</body>
</html>
当然也可以给每个table对象一个id号来引用而不是通过all来引用:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
<iframe src="Noname2.html" id=test>
</iframe>
<BR>
<TABLE id=table1>
<TR>
<TD>abc</TD>
<TD>def</TD>
</TR>
<TR>
<TD>ghi</TD>
<TD>jkl</TD>
</TR>
</TABLE>
<BR><BR>
<TABLE id=table2>
<TR>
<TD>123</TD>
<TD>456</TD>
</TR>
<TR>
<TD>789</TD>
<TD>000</TD>
</TR>
</TABLE>
<BR>
<BR>
<button onclick="show1()">test1</button>
<button onclick="show2()">test2</button>
<SCRIPT LANGUAGE="JavaScript">
<!--
function show1()
{
//把当前页面第一个表格写到iframe里面
test.document.body.innerHTML = table1.outerHTML
}
function show2()
{
//把当前页面第二个表格写到iframe里面
test.document.body.innerHTML = table2.outerHTML
}
//-->
</SCRIPT>
</body>
</html>
andysern(风亦),呵,呵.如果我能提前知道表格是什么样子的,我还用通过函数动态的插入吗?直接写入不就行了?:-)
lonelyghost() 你的方法,让我想到如何在同一网页内插入的东东的办法了,谢谢
emu(ston) :太谢谢了。