在页面里套用了一个iframe,然后动态给iframe添加了一个div,给设置为可编辑状态,怎么能让程序运行的时候鼠标的焦点就在这个div中?还有一个问题是如果我运行页面,然后全选删除,那么那个div也跟着删掉了 ,有什么方法可以保留这个div么?
解决方案 »
- .net新手、、 什么是 动态 语言?
- 如何将打印机配置保存成文件,以及从文件读取配置?
- 买视频会议系统
- winform 做类似于资源管理器的窗口
- C#简单的问题
- 请问为什么在本机上不能下载邮件的附件,而在asp.net空间上确能下载啊?谢谢!问题解决后马上结贴!
- 高手救我!关于case语句的问题!
- [求助]C# winform 实现滚屏显示 类似股市行情
- c# toolStripButton.DoDragDrop拖动问题
- 关于二进制流的Deserialize问题!
- 在线等 发生了 System.NullReferenceException
- 在将 varchar 值 'System.Web.UI.WebControls.TextBox' 转换成数据类型 int 时失败。
document.getElementById("iframe1").contentWindow.document.getElementById("div1").focus();
我这个div 是用Js加进去的,这么写总是报脚本错误
document.getElementById(...).contentWindow.document.write(.' 为空或不是对象
<script type="text/javascript">
window.onload = function () {
document.getElementById("showValue").contentWindow.document.write("<html><body style='margin:0px'><div id='showMSG' style='color:<%=color %>;font-size:<%=size %>px;font-family:<%=font %>;word-spacing:5px;letter-spacing:2px;padding:0px;margin:0px; line-height:20px;z-index:100;background:#fff;left:0;top:0;work-wrap:break-word;overflow:hidden' scrolling='no' onload='this.height=showValue.document.body.scrollHeight+20' > </div></body></html>");
document.getElementById("showValue").contentWindow.document.getElementById("showMSG").focus();
document.getElementById("showValue").contentWindow.document.designMode = "on";
document.getElementById("showValue").contentWindow.document.contentEditable = true;
}
</script> 这个是我的js代码,设置focus了可是还是不好用有哪位知道是什么原因?
<script type="text/javascript">
window.onload = function() {
document.getElementById("showValue").contentWindow.document.write("<html><body style='margin:0px'><div id='showMSG' style='border:solid 1px #ccc;' ></div></body></html>");
//document.getElementById("showValue").contentWindow.document.getElementById("showMSG").innerHTML="aaaa";
document.getElementById("showValue").contentWindow.document.getElementById("showMSG").contentEditable = "true";
document.getElementById("showValue").contentWindow.document.getElementById("showMSG").focus();
//document.getElementById("showValue").contentWindow.document.designMode = "on";
}
</script>
我再最后设置了focus也是不好用啊初始的时候还是不能捕获鼠标,我现在把代码进行了调整,第二个问题解决了,代码如下:
<script type="text/javascript">
window.onload = function () {
document.getElementById("showValue").contentWindow.document.write("<html><body style='margin:0px;color:<%=color %>;font-size:<%=size %>px;font-family:<%=font %>;word-spacing:5px;letter-spacing:2px;padding:0px;margin:0px; line-height:20px;z-index:100;background:#fff;left:0;top:0;work-wrap:break-word;overflow:hidden' scrolling='no' onload='this.height=showValue.document.body.scrollHeight+20'></body></html>");
document.getElementById("showValue").contentWindow.document.designMode = "on";
document.getElementById("showValue").contentWindow.document.contentEditable = true;
document.getElementById("showValue").contentWindow.focus();
}
</script>