我用到了一个iframe
希望在给他添加一个onkeydown事件,以便给一个hidden赋值
代码如下 <iframe id="message" marginwidth="0" marginheight="0" width="100%" height="250px"
style="border-style: solid; border-width: 1px; border-color: Gray; border-bottom-width: 0px;"
frameborder="0"></iframe>
<input name="HtmlEditor1" type="hidden" id="HtmlEditor1"
runat="server" />
<script language="javascript" type="text/javascript">
function initframe()
{
message.document.designMode="On";
message.document.body.onkeydown=function setContent()
{
document.getElementById("HtmlEditor1").value = message.document.body.innerHTML ;
}
}
window.onload=initframe;
</script>却无法给该HtmlEditor1赋值,望指出错误,给出正解
希望在给他添加一个onkeydown事件,以便给一个hidden赋值
代码如下 <iframe id="message" marginwidth="0" marginheight="0" width="100%" height="250px"
style="border-style: solid; border-width: 1px; border-color: Gray; border-bottom-width: 0px;"
frameborder="0"></iframe>
<input name="HtmlEditor1" type="hidden" id="HtmlEditor1"
runat="server" />
<script language="javascript" type="text/javascript">
function initframe()
{
message.document.designMode="On";
message.document.body.onkeydown=function setContent()
{
document.getElementById("HtmlEditor1").value = message.document.body.innerHTML ;
}
}
window.onload=initframe;
</script>却无法给该HtmlEditor1赋值,望指出错误,给出正解
在asp。net未求到答案,难道这里也不可以?????
<!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>
<title>123</title>
<style type="text/css">
</style>
</head>
<body>
<iframe id="message" marginwidth="0" marginheight="0" width="100%" height="250px"
style="border-style: solid; border-width: 1px; border-color: Gray; border-bottom-width: 0px;"
frameborder="0"></iframe>
<input type="hidden" id="HtmlEditor1"/><input type="button" value="getText" id="gettext"/>
</body>
<script language="javascript" type="text/javascript">
function initframe()
{
var message=document.getElementById("message").contentWindow;//要用contentWindow属性才能取到iframe窗口
message.document.designMode="On";
message.document.onkeyup=function()//直接加到document上,用onkeyup 才能正确取值
{
document.getElementById("HtmlEditor1").value = message.document.body.innerHTML ;
}
document.getElementById("gettext").onclick=function(){alert(document.getElementById("HtmlEditor1").value);}
}
window.onload=initframe;
</script>
</html>
最近不常上,感觉人气不很旺了
不过还是要谢谢你