Wie zu entfernen oder Box anhängen?
Frage
Ich versuche, eine Box i in jQuery anhängen zu entfernen, aber ich kann es nicht removet bekommen, nachdem ich hinzufügen, sombody kann mir sagen, was ich 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();
}
Lösung
function appendBox( id )
{
$("#listContainer").append("<div id=\"appendbox-"+ id +"\"><a href=\"javascript:removeBox("+ id +");\">remove</a></div>");
}
function removeBox( id )
{
$("#appendbox-"+ id ).slideUp();
}
#appendbox [etwas] bedeutet nicht, „das Element der ID appendbox [etwas]“, sondern viele verschiedene Dinge je nach etwas.
Andere Tipps
Für ein voll funktionsfähiges Skript müssen Sie die Parameter wickeln in einfachen Anführungszeichen removeBox
, weil es einen String will. javascript:removeBox('"+ id +"');
sonst versucht es, eine Variable zu senden, die nicht existiert
function appendBox( id )
{
$("#listContainer").append("<div id=\"appendbox-"+ id +"\"><a href=\"javascript:removeBox('"+ id +"');\">remove</a></div>");
}
function removeBox( id )
{
$("#appendbox-"+ id ).slideUp();
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow