17
<div class="row-container" data-i="'+data[i].product_id+'">
<div class="row-container" data-i="'+data[i].product_id+'">
<div class="row-container" data-i="'+data[i].product_id+'">
<div class="row-container" data-i="'+data[i].product_id+'">

特定のproduct_idを含む行コンテナを削除したい。data('i')が値を取得することは知っていますが、そこからどこに行くべきかわかりません。

4

3 に答える 3

38
$('.row-container').filter(function(){
    return $(this).data('i') === "product_id"
}).remove();

.data文字列(関数とオブジェクト)のほかに他の変数を設定および取得できます

これを使用することもできます:

$('.row-container').filter('[data-i="product_id"]').remove();

または1つのセレクターで:

$('.row-container[data-i="product_id"]').remove();

"product_id"(実際の値のプレースホルダーはどこにありますか...)

于 2012-05-21T19:14:54.780 に答える
5

あなたが使用することができますfilter()

var $div = $(".row-container").filter(function() {
    return $(this).data("i") == value; // where value == product id to find
});
$div.remove();
于 2012-05-21T19:14:53.513 に答える
4

jQueryには、探している要素を見つけるために使用できる属性セレクターがあります。

$('div.row-container[data-i="<value>"]');
于 2012-05-21T19:15:30.330 に答える