function sentIframeData(){
HtmlEdit.document.body.innerHTML=document.form1.TextBox1.value;
}
HtmlEdit是一个iframe的id,另一个页面也是这句话,但是没出错,为什么这个页面就出错呢,说HtmlEdit.document.body缺少对象.......有兴趣的可以看下面的完整代码前台<%@ Page Language="C#" AutoEventWireup="true" CodeFile="read.aspx.cs" Inherits="table_read" ValidateRequest="false"%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript">
// <!CDATA[function sentIframeData(){HtmlEdit.document.body.innerHTML=document.form1.TextBox1.value;
}// ]]>
</script>
</head>
<body>
<form id="form1" runat="server">
<div> <div style="z-index: 102; left: 10px; width: 712px; position: absolute; top: 18px;
height: 41px">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="保存" Width="63px" />
<asp:TextBox ID="TextBox1" runat="server" Width="487px"></asp:TextBox>
<textarea id="TextArea1" cols="20" rows="2"></textarea></div>
<br />
<br />
<br />
<br />
<br />
<iframe id="ET" style="WIDTH: 100%; HEIGHT: 507px" marginwidth="0" marginheight="0" scroll="auto">
</iframe>
</div>
</form>
</body>
</html>后台 kidduse kd = new kidduse();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string myWriter = kd.getvalue<string>("select url from tt where id=10", 0);
TextBox1.Text = myWriter;
Page.RegisterStartupScript("ggg", "<script>sentIframeData();</script>");
}
}
document.getElementById("HtmlEdit").contentWindow.document.body.innerHTML=document.form1.TextBox1.value;
document.getElementById("HtmlEdit").contentWindow.
document.getElementById("HtmlEdit").contentWindow.document
document.getElementById("HtmlEdit").contentWindow.document.body
或者
document.getElementById("HtmlEdit").contentWindow.document.body.innerHTML=document.form1.TextBox1.value;
2.把HtmlEdit定义成name
尝试下在window.onload去调用sentIframeData();