2013-08-31 27 views
4

我用https://github.com/aehlke/tag-it這個插件的自動完成標記刪除tagLabel輸入場與TAG-IT

用戶只需可以採取標籤了現有陣列sampleTags

之前的標籤添加我檢查一下是否元素是否在數組中

beforeTagAdded: function(evt, ui) { 
       var counter = jQuery.inArray(ui.tagLabel, sampleTags); 

       if (counter != -1) { return true; } 
     else { alert('This word is not in array'); return false; } 
}, 

但是輸入不會被刪除。

我該怎麼做?

的jsfiddle:http://jsfiddle.net/zqDXL/3/

+0

你能解釋更多的哪個輸入應該刪除,什麼時候?順便說一句,格吉不在那裏:) – Sergio

+0

:)!例如如果你輸入'Klav',你可以選擇'Klavier'。但是當你輸入'klaw'並按下回車鍵時,警報就會打開,但'klaw'不會被刪除! – Susanne92

+0

非常感謝! – Susanne92

回答

2

試試這個:

if (counter != -1) { 
    return true; 
} else { 
    alert('This word is not in array'); 
    $('.tagit-new input').val(''); 
    return false; 
} 

演示here