Comment supprimer ou ajouter boîte?
Question
J'essaie de retirer une boîte i append jQuery, mais je ne peux pas obtenir removet après que j'ajouter, sombody peut me dire ce que je dit worng?
function appendBox( id )
{
$("#listContainer").append("<div id=\"appendbox["+ id +"]\"><a href=\"javascript:removeBox("+ id +");\">remove</a></div>");
}
function removeBox( id )
{
$("#appendbox["+ id +"]").slideUp();
}
La solution
function appendBox( id )
{
$("#listContainer").append("<div id=\"appendbox-"+ id +"\"><a href=\"javascript:removeBox("+ id +");\">remove</a></div>");
}
function removeBox( id )
{
$("#appendbox-"+ id ).slideUp();
}
#appendbox [quelque chose] ne signifie pas « l'élément id appendbox [quelque chose] » mais beaucoup de choses différentes en fonction de quelque chose.
Autres conseils
Pour un script entièrement fonctionnel dont vous avez besoin pour envelopper le paramètre à removeBox
guillemets simples car il veut une chaîne. javascript:removeBox('"+ id +"');
sinon il tente d'envoyer une variable qui n'existe pas
function appendBox( id )
{
$("#listContainer").append("<div id=\"appendbox-"+ id +"\"><a href=\"javascript:removeBox('"+ id +"');\">remove</a></div>");
}
function removeBox( id )
{
$("#appendbox-"+ id ).slideUp();
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow