发布于 2016-12-26 23:55:08 | 65 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

CodeMirror 在线代码编辑器

CodeMirror 是一款“Online Source Editor”,基于Javascript,短小精悍,实时在线代码高亮显示,他不是某个富文本编辑器的附属产品,他是许多大名鼎鼎的在线代码编辑器的基础库。


最近用CodeMirror2作后台的模板编辑器,在IE9、Firefox下面没有问题。到了IE7、IE8下面,textarea里面的代码就显示不出来了。搜索了好多,终于找到原因
原来出错的代码如下:
 
<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> 


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务