原来出错的代码如下:
复制代码 代码如下:
出错的原因应该是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,即可正常:
复制代码 代码如下:
