2008-10-18 48 views
3

我在Firefox 3.03的DIV元素上使用contentEditable屬性。如果將其設置爲true,則可以按預期編輯DIV的文本內容。Firefox 3.03和contentEditable

然後,當我將contentEditable設置爲「false」時,div也不再可編輯,也如預期的那樣。

但是即使文本不再可編輯,閃爍的插入符號(文本輸入光標)仍然可見。當我單擊同一頁面中的大多數其他文本時,即使在普通文本段落中,插入符號現在也可見。

有沒有人見過這個?有什麼方法可以強制插入符號隱藏嗎?

(當我要麼調整瀏覽器或其他應用程序中單擊,然後回來,插入符奇蹟般地消失。)

回答

6

我已經經歷了這一點,我的解決方法是清除選擇當我停用CONTENTEDITABLE:

if ($.browser.mozilla) { // replace with browser detection of your choice 
    window.getSelection().removeAllRanges(); 
} 

我其實去除 「CONTENTEDITABLE」 屬性比IE等瀏覽器,而不是將其設置爲false:

if ($.browser.msie) { 
    element.contentEditable = false; 
} 
else { 
    $(element).removeAttr('contenteditable'); 
} 

瀏覽器不一致地管理contentEditable屬性,我的測試顯示這在整體上運行得更好。我不記得這是否有助於修復脫字號問題,但爲了以防萬一,我將它扔到了這裏。

+0

感謝您的提示。 removeAllRanges()至少似乎隱藏插入符號設置可編輯爲false後,好一點。然而,如果我點擊文本的其他地方,它會再次回來。刪除屬性本身似乎沒有任何影響。 可能是Mozilla可以在新版本中修復的問題。 – Ash 2008-10-19 23:28:32

0

可以在Firefox中使用樣式屬性-moz-user-input以獲得功能contenteditable=false的工作。
分配的值定義用戶輸入是否被接受。可能的值是

none  : The element does not respond to user input. 
enabled : The element can accepts user input. This is default. 
disabled : The element does not accept user input. 

例如爲:

// to disallow users to enter input 
<asp:TextBox ID="uxFromDate" runat="server" style="-moz-user-input: disabled;"></asp:TextBox> 

// to allow users to enter input 
<asp:TextBox ID="uxFromDate" runat="server" style="-moz-user-input: enabled ;"></asp:TextBox> 

參見https://developer.mozilla.org/en/CSS/-moz-user-input供進一步參考。

0

這解決了ploblem,看起來像Firefox僅是檢查是用自己的方式讓事情:P

getDoc().designMode = "off"; 
相關問題