0

これが私のコードです:

jQuery("#test").after("<a id='clearall' href='#' onclick='jQuery(this).remove(); jQuery('.clearselection').remove;'><img src='clearselection.gif'></a>");

これを試すと、構文エラーが発生します。

jQuery(this).remove(); jQuery(<---

リンクをクリックしたら、リンク イメージを削除し、その Class .clearselection のすべてのインスタンスを削除する必要があります。一重引用符をエスケープしようとしましたが、うまくいきませんでした。どんな助けでも大歓迎です。

4

2 に答える 2

2

クリック ハンドラーをインラインで定義する代わりに、jquery を使用してそれを処理します。

$(document).on("click", "#clearall", function()
{
   jQuery(this).remove(); 
   jQuery('#clearselection').remove(); //btw you were missing the parens here
});
于 2013-04-19T19:06:57.987 に答える
0

これを置き換えます:

onclick='jQuery(this).remove(); jQuery(\'.clearselection\').remove();'
于 2013-04-19T19:07:43.570 に答える