2011-12-04 97 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

完美!谢谢 –