CodeMirror2 IE7/IE8 下面未知運(yùn)行時(shí)錯(cuò)誤的解決方法
更新時(shí)間:2012年03月29日 01:45:19 作者:
最近用CodeMirror2作后臺(tái)的模板編輯器,在IE9、Firefox下面沒有問題。到了IE7、IE8下面,textarea里面的代碼就顯示不出來了。搜索了好多,終于找到原因
原來出錯(cuò)的代碼如下:
<p style="margin-top:0;">
<asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" Height="450" Width="98%"></asp:TextBox>
</p>
出錯(cuò)的原因應(yīng)該是IE7、IE8中的P不支持innerHTML。CodeMirror的作者也發(fā)現(xiàn)了這個(gè)問題,相關(guān)鏈接:
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(/運(yùn)行時(shí)/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>
復(fù)制代碼 代碼如下:
<p style="margin-top:0;">
<asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" Height="450" Width="98%"></asp:TextBox>
</p>
出錯(cuò)的原因應(yīng)該是IE7、IE8中的P不支持innerHTML。CodeMirror的作者也發(fā)現(xiàn)了這個(gè)問題,相關(guān)鏈接:
https://github.com/marijnh/CodeMirror2/issues/215
https://github.com/marijnh/CodeMirror2/commit/4886415d6054571f92fa4d5601ebe7d601e952ab
復(fù)制代碼 代碼如下:
try { stringWidth("x"); }
catch (e) {
if (e.message.match(/runtime/i) || e.message.match(/運(yùn)行時(shí)/i) )
e = new Error("A CodeMirror inside a P-style element does not work in Internet Explorer. (innerHTML bug)");
throw e;
}
把textarea外層的p改成div,即可正常:
復(fù)制代碼 代碼如下:
<div style="margin-top:0;">
<asp:TextBox ID="txtContent" runat="server" TextMode="MultiLine" Height="450" Width="98%"></asp:TextBox>
</div>
您可能感興趣的文章:
相關(guān)文章
js利用for in循環(huán)獲取 一個(gè)對(duì)象的所有屬性以及值的實(shí)例
下面小編就為大家?guī)硪黄猨s利用for in循環(huán)獲取 一個(gè)對(duì)象的所有屬性以及值的實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-03-03
原生JS實(shí)現(xiàn)ajax與ajax的跨域請(qǐng)求實(shí)例
下面小編就為大家分享一篇原生JS實(shí)現(xiàn)ajax與ajax的跨域請(qǐng)求實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2017-12-12
詳解JavaScript基于面向?qū)ο笾畡?chuàng)建對(duì)象(1)
這篇文章主要介紹了JavaScript基于面向?qū)ο笾畡?chuàng)建對(duì)象,對(duì)創(chuàng)建對(duì)象進(jìn)行了詳細(xì)描述,感興趣的小伙伴們可以參考一下2015-12-12
一個(gè)判斷搶購時(shí)間是否到達(dá)的簡單的js函數(shù)
這篇文章主要介紹了一個(gè)簡單的判斷搶購時(shí)間是否到達(dá)的js函數(shù),原理很簡單,找到時(shí)鐘的id,計(jì)算數(shù)值,到達(dá)搶購時(shí)間時(shí)執(zhí)行任務(wù),需要的朋友可以參考下2014-06-06
javascript的trim,ltrim,rtrim自定義函數(shù)
今天用到j(luò)avascript去掉一個(gè)文本框中字符串兩端的空格,開始還以為有trim,ltrim,rtrim函數(shù)(asp中有這三個(gè)函數(shù),弄混了),結(jié)果找半天,沒有找到。最后找到用正則實(shí)現(xiàn)這樣功能的自定義函數(shù)。2008-09-09

