我用到了一个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赋值,望指出错误,给出正解
因为这是在一个用户控件中
我在后台这样写的 public string Content
{
get { return HtmlEditor1.Value.ToString(); }
set { HtmlEditor1.Value = value; }
}然后我可以再引用该控件的页面来获取该iframe的内容
当然可以给出好的解决方法
<script language="javascript" type="text/javascript">
function initframe() {
debugger
document.getElementById('message').document.designMode="On";
document.getElementById('message').document.body.onkeydown = function setContent() {
document.getElementById('HtmlEditor1').value = document.getElementById('message').document.body.innerHTML;
}
}
window.onload=initframe;
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function initframe() {
debugger
document.getElementById('message').document.designMode="On";
document.getElementById('message').document.body.onkeydown = function setContent() {
document.getElementById('HtmlEditor1').value = document.getElementById('message').document.body.innerHTML;
}
}
window.onload=initframe;
</script></head>
<body>
<form id="form1" runat="server">
<div>
<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"/>
<input name="HtmlEditor2" type="button" id="HtmlEditor2" value="GetValue" onclick="alert(document.getElementById('HtmlEditor1').value)"/> </div>
</form>
</body>
</html>
点击GetValue 试试看
function initframe() {
debugger
message.document.designMode = "On";
message.document.onkeyup = function setContent() {
document.getElementById('HtmlEditor1').value = message.document.body.innerHTML;
}
}
window.onload=initframe;
</script>
这个可能才是你想要的
浏览器IE8
赋值你的代码,可是我无法选中iframe ,即我不能输入值
故也不能测试,为什么??
谢谢了
只是可惜了我这个问题没有解决啊
无奈。
这个问题我在JavaScript版搞定了
谢谢了