在线等,解决就给分:如何提交iframe中的值?
KBUG 2003-03-11 07:36:43 页面代码如下:
1个叫 form1的表格
内含一个叫 editor的iframe
我希望得到iframe的值 怎么做?
<table align="center" width="99%" cellpadding="0" cellspacing="0" border="1" bordercolor="#CCCCCC" height="311">
<!-- 表格开始 -->
<form action="add.php" method="post" name="form1" >
<tr>
<td align="middle" colspan="2" class="s9back" height="208">
<input type="hidden" name="content"><!-- 隐藏提交的两个变量 -->
<input type="hidden" name="body" ID=Hidden1>
<script>
// strHTML是编辑器的内容
strHTML="";
if((window.navigator.userAgent.indexOf("IE 5") > 1) || (window.navigator.userAgent.indexOf("IE 6") > 1))
{
// 编辑框
document.write('<iframe ID="editor" NAME="editor" style="width: 500; height:400;display:none"></iframe>');
// 仿FrontPage界面
document.write('<div id="switchDiv" style="padding: 0;margin: 0;width: 500"><table border="0" cellspacing="0" cellpadding="0" width="100%" style="background-color:buttonface">');
document.write('<tr><td id="status1"><map name="switch1">');
document.write('<area onclick="switchstatus(2)" shape="polygon" coords="50, 1, 46, 7, 50, 14, 90, 14, 95, 2">');
document.write('<area onclick="switchstatus(3)" shape="polygon" coords="128, 13, 134, 0, 96, 0, 93, 10, 96, 14">');
document.write('</map><img SRC="images/normal.gif" height="15" width="135" usemap="#switch1" border="0">');
document.write('</td><td id="status2" style="display:none"><map name="switch2">');
document.write('<area onclick="switchstatus(1)" shape="polygon" coords="5, 3, 12, 14, 43, 14, 49, 6, 43, 0">');
document.write('<area onclick="switchstatus(3)" shape="polygon" coords="97, 0, 94, 7, 98, 14, 127, 14, 134, 0">');
document.write('</map><img SRC="images/html.gif" height="15" width="135" usemap="#switch2" border="0">');
document.write('</td><td id="status3" style="display:none"><map name="switch3">');
document.write('<area onclick="switchstatus(1)" shape="polygon" coords="3, 2, 10, 14, 41, 14, 50, 0">');
document.write('<area onclick="switchstatus(2)" shape="polygon" coords="87, 14, 91, 5, 87, 0, 50, 0, 46, 9, 49, 14">');
document.write('</map><img SRC="images/preview.gif" height="15" width="135" usemap="#switch3" border="0"></td>');
document.write('<td><img src="images/scrolll.gif" height=15 width=24></td><td width="100%" style="background-color:white;filter:Alpha(opacity=50);"> </td><td><img src="images/scrollr.gif" height=15 width=24></td></tr></table></div>');
}
// 状态切换
function switchstatus(flag){
document.frames.editor.frames.edit1.swapModes(flag);
var i;
for(i=1;i<4;i++){
document.all["status" + i].style.display = "none";
}
document.all["status" + flag].style.display = "block";
}
// document.all是该HTML文档上的元素数组
// 关闭窗口
function winhidden(){
if (confirm("您确信要放弃所有改动退出吗?\n退出后将无法保存您所做的改动。")){
document.all.editor.src = "";
window.close();
}
}
// 编辑器初始化
function win_init(){
document.all.editor.src = "edit.htm";
window.status = "程序载入中,请等待……";
}
function save(){
document.frames.editor.savefile();
}
window.onload = win_init
function UploadComplete(URL){
if ((URL != null) && (URL != ""))
if (URL.indexOf(":") == -1)
doFormat("InsertImage", "http://" + URL);
else
doFormat("InsertImage", URL);
document.all.UploadImg.style.display = "none";
document.forms["upload"].reset();
}
function sends()
{
document.form1.content.value='25';
//可以将25提交出去
// 用什么来获得iframe-editor的值?
// 下面的几种方法好像不行~
// 应该怎么写呢? 为什么下边的方法不可以?
//document.form1.content.value=editor.document.body.innerHTML;
//document.form1.content.value=document.all.editor.innerHTML;
//document.form1.content.value=document.form1.editor.getHTML();
}
</script>
</td>
</tr>
<tr bgcolor="#8dbceb">
<td align="middle" colspan="2" class="pt10" height="28">
<div align="center">
<input type="submit" name="Submit225" value="发布" onclick="javascript:{alert('send');sends();}" >
<input type="button" value="返回" name="B3" onclick="javascript:window.location.href='../index.html'">
</div>
</td>
</tr>
</form>
</table>