jQuery tag-it, come eseguire il post quando è rimosso l'articolo
-
28-10-2019 - |
Domanda
Sto usando lo script jQuery tag-it, può essere visualizzato qui:
http://levycarneiro.com/projects/tag-it/example.html
Lo script originariamente non viene fornito con l'opzione per inviare post dei tag aggiunti o rimuovere i tag che l'utente rimuove.
Ho aggiunto correttamente la richiesta post a uno script PHP in modo che quando qualcuno aggiunge un tag, lo inserisce nel DB.
Il problema è che quando qualcuno fa clic sul pulsante "X" per rimuovere uno dei tag, non riesco a trovare un modo per ottenere il valore effettivo del tag ..
Soluzione
Ecco il codice modificato in modo da poter avere accesso al tag che viene rimosso ..
Nel click
gestore (del X)
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();
}
e nel keypress
Uso del gestore
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();
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow