CodeMirror2 IE7/IE8 下面未知運(yùn)行時(shí)錯(cuò)誤的解決方法
更新時(shí)間:2012年03月29日 01:45:19 作者:
最近用CodeMirror2作后臺(tái)的模板編輯器,在IE9、Firefox下面沒(méi)有問(wèn)題。到了IE7、IE8下面,textarea里面的代碼就顯示不出來(lái)了。搜索了好多,終于找到原因
原來(lái)出錯(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è)問(wèn)題,相關(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è)問(wèn)題,相關(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)文章
Javascript函數(shù)緩存的實(shí)現(xiàn)及應(yīng)用場(chǎng)景
Javascript函數(shù)緩存是一種提高網(wǎng)頁(yè)性能的重要技術(shù),通過(guò)將函數(shù)結(jié)果存儲(chǔ)在緩存中,避免重復(fù)計(jì)算,從而提高頁(yè)面加載速度和響應(yīng)速度,本文主要介紹了Javascript函數(shù)緩存的實(shí)現(xiàn)及應(yīng)用場(chǎng)景,具有一定的參考價(jià)值,感興趣的可以了解一下2023-12-12關(guān)于Mozilla瀏覽器不支持innerText的解決辦法
在各大瀏覽器中,除Mozilla瀏覽器外,幾乎都支持一個(gè)元素的屬性:innerText。我們可以通過(guò)它來(lái)快速獲取某個(gè)元素的內(nèi)的文本。2011-01-01判斷js數(shù)據(jù)類(lèi)型的函數(shù)實(shí)例詳解
這篇文章主要介紹了一個(gè)判斷js數(shù)據(jù)類(lèi)型的函數(shù),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-05-05無(wú)語(yǔ),javascript居然支持中文(unicode)編程!
無(wú)語(yǔ),javascript居然支持中文(unicode)編程!...2007-04-04

javascript中attachEvent用法實(shí)例分析
這篇文章主要介紹了javascript中attachEvent用法,實(shí)例分析了javascript中事件綁定的相關(guān)技巧,需要的朋友可以參考下
2015-05-05 
javascript控制圖片播放的實(shí)現(xiàn)代碼
這篇文章主要介紹了javascript控制圖片播放的實(shí)現(xiàn)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
2015-08-08 
JavaScript中高階函數(shù)的巧妙運(yùn)用
JavaScript中的高階函數(shù)是指可以接受其他函數(shù)作為參數(shù)或者返回一個(gè)函數(shù)作為結(jié)果的函數(shù),本文介紹了JS中一些高階函數(shù)的妙用,希望對(duì)大家有所幫助
2023-05-05