信息发布→ 登录 注册 退出

CodeMirror2 IE7/IE8 下面未知运行时错误的解决方法

发布时间:2026-01-11

点击量:
原来出错的代码如下:
复制代码 代码如下:
<p style="margin-top:0;">
<asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" Height="450" Width="98%"></asp:TextBox>
</p>

出错的原因应该是IE7、IE8中的P不支持innerHTML。CodeMirror的作者也发现了这个问题,相关链接:
  https://github.com/marijnh/CodeMirror2/issues/215
  https://github.com/marijnh/CodeMirror2/commit/4886415d6054571f92fa4d5601ebe7d601e952ab
复制代码 代码如下:
try { stringWidth("x"); }
catch (e) {
if (e.message.match(/runtime/i) || e.message.match(/运行时/i) )
e = new Error("A CodeMirror inside a P-style element does not work in Internet Explorer. (innerHTML bug)");
throw e;
}

把textarea外层的p改成div,即可正常:
复制代码 代码如下:
<div style="margin-top:0;">
<asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" Height="450" Width="98%"></asp:TextBox>
</div>
标签:# innerHTML  # runat  # txtContent  # gt  # lt  # span  # BR  # top  # margin  # style  # TextMode  # 未知运行  # Height  # MultiLine  # Width  # 发现了  # 应该是  # 者也  # 相关链接  # 不支持  # 这个问题  # codeMirror插件使用讲解  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!