在线等,解决就给分:如何提交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>
...全文
135 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
KBUG 2003-03-11
  • 打赏
  • 举报
回复
<td style="width: 4;" width="12"><img src="images/separator.gif" WIDTH="2" HEIGHT="18"></td>
<td class="coolButton" onclick="doFormat('BackColor',bkcolorimg.style.backgroundColor)" title="突出显示颜色" width="19">
<img src="images/colorpen.gif" width="16" height="16" style="background-color:#FFFFFF" id=bkcolorimg></td>
<td class="coolButton" onclick="palette(bkcolorimg)" title="选择突出显示颜色" style="font: 5pt;width:3pt;" width="15">▼</td>
<td class="coolButton" onclick="doFormat('ForeColor',colorimg.style.backgroundColor)" title="字体颜色" width="19"><img src="images/fontcolor.gif" width="16" height="16" style="background-color:#000000" id=colorimg></td>
<td class="coolButton" onclick="palette(colorimg)" title="选择字体颜色" style="font: 5pt;width:3pt;" width="15">▼</td>

<td style="width: 4;" width="10"><img src="images/separator.gif" WIDTH="2" HEIGHT="18"></td>
<td class="coolButton" onclick="return false;showHelp()" title="帮助" width="23" align="center"><img src="images/help.gif" width="16" height="16"></td>
</tr>
</table>
<iframe height=0 width=0 style="visibility: hidden" id=uploadback name=uploadback></iframe>
<table id="editbar1" class="coolBar" cellspacing="0" cellpadding="0" style="font-weight: bold; border: 0 solid buttonface;z-index=3;display:block;" width="487">
<tr>
<td style="width: 3;" width="4"> </td>
<td class="coolButton" onclick="doFormat('Outdent')" title="减小缩进" width="17"><img src="images/outdent.gif" WIDTH="16" HEIGHT="16"></td>
<td class="coolButton" onclick="doFormat('Indent')" title="增加缩进" width="17"><img src="images/indent.gif" WIDTH="16" HEIGHT="16"></td>
<td class="coolButton" onclick="doFormat('InsertHorizontalRule')" title="插入水平线" width="17"><img src="images/hr.gif" WIDTH="16" HEIGHT="16"></td>
<td style="width: 4;" width="5"><img src="images/separator.gif" WIDTH="2" HEIGHT="18"></td>
<td class="coolButton" onclick="doFormat('FormatBlock','<OL>')" title="编号" width="17"><img src="images/ol.gif" WIDTH="16" HEIGHT="16"></td>
<td class="coolButton" onclick="doFormat('FormatBlock','<UL>')" title="项目符号" width="17"><img src="images/ul.gif" WIDTH="16" HEIGHT="16"></td>
<td style="width: 4;" width="5"><img src="images/separator.gif" WIDTH="2" HEIGHT="18"></td>
<td class="coolButton" onclick="addTable()" title="插入表格" width="17"><img src="images/table.gif" WIDTH="16" HEIGHT="16"></td>
<td style="width: 4;" width="5"><img src="images/separator.gif" WIDTH="2" HEIGHT="18"></td>
<td class="coolButton" onclick="doFormat('RemoveFormat')" title="去除格式" width="17"><img src="images/unformat.gif" WIDTH="16" HEIGHT="16"></td>
<td style="width: 4;" width="5"><img src="images/separator.gif" WIDTH="2" HEIGHT="18"></td>
<td id="formatSelect" style="padding: 0;" title="段落格式" width="88">
<select onchange="doSelectClick('FormatBlock',this);this.returnValue=false;" style="font: icon; width: 80px;" id="select1" name="select1">
<option>段落格式</option>
<option VALUE="<P>">普通
<option VALUE="<PRE>">已编排格式
<option VALUE="<H1>">标题一
<option VALUE="<H2>">标题二
<option VALUE="<H3>">标题三
<option VALUE="<H4>">标题四
<option VALUE="<H5>">标题五
<option VALUE="<H6>">标题六
<option VALUE="<H7>">标题七
</select>
</td>
<td id="fontSelect" style="padding: 0;" title="字体" width="58">
<select onchange="doSelectClick('FontName',this);" style="font: icon; width: 50px;">
<option>字体</option>
<option VALUE="宋体">宋体
<option VALUE="楷体_GB2312">楷体
<option VALUE="隶书">隶书
<option VALUE="黑体">黑体
<option VALUE="仿宋_GB2312">仿宋
</select>
</td>
<td id="sizeSelect" style="padding: 0;" title="字体大小" width="83">
<select onchange="doSelectClick('FontSize',this);" style="font: icon; width: 75px;">
<option>字体大小</option>
<option VALUE="1">1
<option VALUE="2">2
<option VALUE="3">3
<option VALUE="4">4
<option VALUE="5">5
<option VALUE="6">6
<option VALUE="7">7
</select>
</td>
<td style="padding: 0;" title="特殊字体格式" width="108">
<select id="specialtype" onchange="doSelectClick('FormatBlock',this);this.returnValue=false;" style="font: icon; width: 100px;">
<option>特殊字体格式</option>
<option VALUE="SUP">上标
<option VALUE="SUB">下标
<option VALUE="DEL">删除线
<option VALUE="BLINK">闪烁
<option VALUE="BIG">增大字体
<option VALUE="SMALL">减小字体
</select>
</td>
<td style="width: 4;" width="10"><img src="images/separator.gif" WIDTH="2" HEIGHT="18"></td>
</tr>
</table>
</td>
<td align="right" width="10">  </td>
<td align="right" class="coolButton" onclick="showmore()" title="更多工具栏" style="padding: 0" id="more" width="1"></td>
</tr></table>
</fieldset>
<iframe ID="edit1" SRC="editor.htm" NAME="myEditor" onfocus="document.all.editbar._editor = window.frames[this.id];" style="width: 100%; height: 90%;"></iframe>
<input type="hidden" name="content">
<input type="hidden" name=body ID=Hidden1>
<iframe id="uploadback" name="uploadback" style="display:none"></iframe>
<script language="javascript">
if((window.navigator.userAgent.indexOf("IE 5") < 1) && (window.navigator.userAgent.indexOf("IE 6") < 1)) {
alert("请使用Microsoft Internet Explorer 5.0\n或更高版本的浏览器!");
window.close();
}
window.onload = init;
window.onresize = fixSize;
document.all.editbar._editor = window.frames[document.all.edit1.id];
document.all.editbar1._editor = window.frames[document.all.edit1.id];
</script>
</body>
</html>
KBUG 2003-03-11
  • 打赏
  • 举报
回复
这个是 edit页面的代码

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>ABC代码 编辑器</title>
<link rel="STYLESHEET" type="text/css" href="htmlediter.css">
<script src="chinacecc.js" language="JScript"></script>
<script language="JavaScript">
//===========================================
//打开图片列表窗口,并设置接收返回值的目标
//===========================================
function openImageList(href) {
var newwin=window.open(href,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=520,height=400");
newwin.focus();
return;
}
//打开附件列表窗
function openFileList(href) {
var newwin=window.open(href,"","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=520,height=400");
newwin.focus();
return;
}
//============================================
//接收返回的图片代码,并插入图片
//============================================
function receiveVal(val) {
UploadComplete(val);
}
//接收返回的文件链接代码,并插入
function receiveFileVal(val) {
myEditor.pasteHTML(val);
}
//-->

</script>
</head>
<body SCROLL="no" STYLE="border: 0pt" bgcolor="white">
<fieldset>
<table border="0" cellspacing="0" cellpadding="0" width="490">
<tr>
<td id="fore" class="coolButton" onclick="showfore()" title="更多工具栏" style="display: none; padding: 0" align="right" width="1"></td>
<td align="left" width="488">
<table id="editbar" class="coolBar" cellspacing="0" cellpadding="0" style="font-weight: bold; border: 0 solid buttonface;z-index=2;" width="486">
<tr>
<td style="width:3px;cursor:move;" width="11"></td>
<td class="coolButton" onclick="doFormat('Bold')" title="粗体" width="19"><img src="images/bold.gif" WIDTH="16" HEIGHT="16"></td>
<td class="coolButton" onclick="doFormat('Italic')" title="斜体" width="19"><img src="images/italic.gif" WIDTH="16" HEIGHT="16"></td>
<td class="coolButton" onclick="doFormat('Underline')" title="下划线" width="19"><img src="images/underline.gif" WIDTH="16" HEIGHT="16"></td>

<td style="width: 4;" width="12"><img src="images/separator.gif" WIDTH="2" HEIGHT="18"></td>
<td class="coolButton" onclick="doFormat('Undo')" title="撤销" width="19"><img src="images/undo.gif" width="16" height="16"></td>
<td class="coolButton" onclick="doFormat('Redo')" title="恢复" width="19"><img src="images/redo.gif" width="16" height="16"></td>

<td style="width: 4;" width="12"><img src="images/separator.gif" WIDTH="2" HEIGHT="18"></td>
<td class="coolButton" onclick="doFormat('JustifyLeft')" title="左对齐" width="19"><img src="images/jleft.gif" WIDTH="16" HEIGHT="16"></td>
<td class="coolButton" onclick="doFormat('JustifyCenter')" title="居中" width="19"><img src="images/jcenter.gif" WIDTH="16" HEIGHT="16"></td>
<td class="coolButton" onclick="doFormat('JustifyRight')" title="右对齐" width="19"><img src="images/jright.gif" WIDTH="16" HEIGHT="16"></td>

<td style="width: 4;" width="12"><img src="images/separator.gif" WIDTH="2" HEIGHT="18"></td>
<td class="coolButton" onclick="doFormat('Cut')" title="剪切" width="19"><img src="images/cut.gif" WIDTH="16" HEIGHT="16"></td>
<td class="coolButton" onclick="doFormat('Copy')" title="复制" width="19"><img src="images/copy.gif" WIDTH="16" HEIGHT="16"></td>
<td class="coolButton" onclick="doFormat('Paste')" title="粘贴" width="19"><img src="images/paste.gif" WIDTH="16" HEIGHT="16"></td>
<td class="coolButton" onclick="doFormat('Delete')" title="删除" width="19"><img src="images/delete.gif" WIDTH="16" HEIGHT="16"></td>

<td style="width: 4;" width="12"><img src="images/separator.gif" WIDTH="2" HEIGHT="18"></td>
<td class="coolButton" onclick="doFormat('CreateLink')" title="插入链结" width="19"><img src="images/link.gif" WIDTH="16" HEIGHT="16"></td>
<td class="coolButton" onclick="openFileList('../../normal/file/filelist.jsp')" title="添加附件"><img src="images/upfiles.gif" WIDTH="16" HEIGHT="16"></td>
<td class="coolButton" onclick="AddImg()" title="插入图片" width="19"><img src="images/image.gif" WIDTH="16" HEIGHT="16"></td>
<form name=upload target=uploadback method="post">
<input type="hidden" name="CopyrightInfo" value="http://www.chinacecc.com" ID=Hidden1>
<td class="coolButton" id=UploadImg style="display: none;width:100;" nowrap width="46">
<input type=button value="选择" onclick="openImageList('../../normal/meta/imagelist.jsp');">
<input type=reset name=reset1 value="取消" style="width:5:height:18" onclick="CancelAddImg()">
</td>
</form>




KBUG 2003-03-11
  • 打赏
  • 举报
回复
是这样的,iframe只有这一句:

document.write('<iframe ID="editor" NAME="editor" style="width: 500; height:400;display:none"></iframe>');

上边没有其他的input,用document.frames("editor").document.all.inputName.value得不到值

不过突然发现
// 编辑器初始化
function win_init(){
document.all.editor.src = "edit.htm";
window.status = "程序载入中,请等待……";
}

调用了edit.htm

edit.htm 有调用了 editor.htm

<iframe ID="edit1" SRC="editor.htm" NAME="myEditor" onfocus="document.all.editbar._editor = window.frames[this.id];" style="width: 100%; height: 90%;"></iframe>

这个是editor页的代码
<HTML>
<HEAD>
<TITLE>richTextEditor</TITLE>
</HEAD>

<STYLE>
BODY {margin: 0pt; padding: 0pt; border: none}
IFRAME {width: 100%; height: 100%; border: none}
</STYLE>

<SCRIPT src=editor.js language=JScript></SCRIPT>

<BODY SCROLL=no>
<IFRAME ID=textEdit></IFRAME>
</BODY>
</HTML>

meizz 2003-03-11
  • 打赏
  • 举报
回复
document.frames("editor").document.all.inputName.value

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧