2012-09-22 59 views
1

可能重複:
Is there a way to make a text area partially editable? (make only portions of the text editable)如何設置readOnly屬性設置所選文本的HTML文本區域內

如何設置readOnly屬性設置所選文本的HTML文本區域內的任何建議。 這裏是內textarea的選定的文本的圖像..

enter image description here

任何的指導和幫助表示讚賞..!

+0

是否可以將readOnly屬性設置爲選定的文本? – super

+3

你有什麼嘗試? '這是textarea內部選定文本的圖像在哪裏? –

+0

請檢查這個小提琴:http://jsfiddle.net/WSrww/ – super

回答

1

從我所瞭解的你想要的,here是一個工作解決方案。

下面是代碼:

$("#my-text").select(function() { 
    $(this).readonly = true; 
}); 
$("#my-text").mouseup(function() { 
    $(this).readonly = false; 
}); 
$("#my-text").keydown(function() { 
    $(this).readonly = false; 
}); 

基本上我利用select事件使textarea的readonly。然後,使用removeAttr刪除click和​​上的read only屬性。

感謝@Bergi指向jQuery對象的readonly屬性。

+0

,只需設置屬性'this.readonly = true/false;'而不是繞過屬性。 – Bergi

+0

它不適用於我,默認情況下,我的代碼將選擇文本「僅」,我想使該文本不可編輯或只讀 – super