2013-03-23 47 views
0

我使用引導可編輯來編輯照片的文本屬性。在默認情況下,它顯示文本,如果您單擊它,將打開帶有可編輯文本的小窗口。我想要做的就是創建一個腳本,它將用鉛筆圖標替換文本。我寫了這個:觀看元素並更改文本的腳本

$('#gallery').delegate('.editable-click', 'need_some_event' , function(){ 
    $(this).text(); 
    $(this).html('<i class="icon-pencil" ></i>'); 
}); //end delegate 

的代碼,我有:

<a class="edit editable editable-click" style="float:left; margin-right: 10px" href="#" rel="Photo_text_183" data-pk="183">some text descrtion of photo</a> 

我想有後:

<a class="edit editable editable-click" style="float:left; margin-right: 10px" href="#" rel="Photo_text_183" data-pk="183"><i class="icon-pencil" ></i></a> 

問題是,可編輯的文本是由另一個JavaScript生成。我基本上需要一些會觀看所有可以點擊的類元素的事件,如果它們出現,請刪除帶有圖標的文本。感謝您的任何建議。

回答

2

也許你可以嘗試監聽DOMNodeInserted

$(document).on('DOMNodeInserted', function(){ 
if($(this).find('.editable-text').length > 0){ 
//do stuff 
} 
}); 

這裏的工作小提琴作爲一個例子http://jsfiddle.net/wvVnQ/1/

因爲,如下所述,這已被棄用,你可以試試這個插件:https://github.com/naugtur/insertionQuery

+0

'DOMNodeInserted'在舊版瀏覽器上無法使用,並且很快就無法在較新的瀏覽器上使用,因爲它已被W3C棄用。 – Alnitak 2013-03-23 20:51:54

+0

好的,謝謝你,會試試 – kokoseq 2013-03-23 21:02:39

+0

我用CSS做到了最後... .edit { \t text-indent:100%; white-space:nowrap; 溢出:隱藏; \t background-image:url(「../ img/glyphicons-halflings.png」); \t width:14px; height:14px; \t background-position:0 -72px; } – kokoseq 2013-03-23 21:23:41