2011-12-04 95 views
1

我使用jQuery的標籤,它的腳本如何執行後,在這裏可以查看:jQuery的標籤,何時項中移除,

http://levycarneiro.com/projects/tag-it/example.html

腳本原本不附帶的選項發送添加標籤的帖子或刪除用戶刪除的標籤。

我成功地將post請求添加到php腳本中,這樣當有人添加標籤時,它會將其插入到數據庫中。

,當有人點擊「X」按鈕來刪除標籤中的一個,我似乎該問題無法找到一種方式來獲得實際的標籤值..

回答

1

下面是修改,以便代碼您可以訪問已移除的標籤..

click處理

if (e.target.tagName == 'A') { 
      // Removes a tag when the little 'x' is clicked. 
      // Event is binded to the UL, otherwise a new tag (LI > A) wouldn't have this event attached to it. 
      var tag = $(e.target).parent(); 
      //console.log(tag.children('input').val()); // this line extracts the tag value 
      tag.remove(); 
     } 

(的X)和keypress處理器使用

if (tag_input.val() == "") { 
       // When backspace is pressed, the last tag is deleted. 
       var tag = $(el).children(".tagit-choice:last"); 
       // console.log(tag.children('input').val()); // this line extracts the tag value 
       tag.remove(); 
      } 

演示在http://jsfiddle.net/gaby/yYHTu/1/

+0

完美!謝謝 –