0

私のコードで間違っていること:

  $.each($("input[value='"+id+"']"), function(index, value) {
            alert($(this).val());
            $("input[value='"+$(this).val()+"']").prevAll('.t-item:first').remove();
        });

HTML スキーマ:

HTML スキーマ

ps私は自分のページの他の場所に同じhtmlを持っているので「それぞれ」をやっているので、両方の場所から削除したい

この HTML の例では、私の ID は 249 または 293 です。

4

4 に答える 4

3

<li class="t-item">マークアップから、入力の祖先を削除しようとしているように見えます。その場合は、.closest()

    $.each($("input[value='"+id+"']"), function(index, value) {
        alert($(this).val());
        $(this).closest('.t-item').remove();
    });
于 2012-09-07T19:31:01.343 に答える
1

試してみてください:

$(this).closest('.t-item').remove();

それ以外の:$("input[value='"+$(this).val()+"']").prevAll('.t-item:first').remove();

http://api.jquery.com/closest

于 2012-09-07T19:32:09.733 に答える
1

あなたは試すことができます:

  $.each($("input[value='"+id+"']"), function(index, value) {
            alert($(this).val());
            $(this).closest('.t-item').remove();
        });

http://api.jquery.com/closest/

Get the first element that matches the selector, beginning at the current element and progressing up through the DOM tree.

于 2012-09-07T19:32:13.237 に答える
0
$("input[value="+id+"]").closest('.t-item').remove();
于 2012-09-07T20:11:57.397 に答える