0

以下に基づいて、h6タグ内のコンテンツをエコーし​​ようとしています:

$('input').keyup( function () {
if ($(this).val() > '0') 
    $('#testh6').append($(this).parents("tr").clone("h6"));
});

問題は、含まれている h6 だけでなく、tr 全体を使用することです。どうすればこれを変更できるので、h6 をクローンするだけですか?

4

1 に答える 1

1

これはそれを行う必要があります:

$('input').keyup( function () {
if ($(this).val() > '0') 
    $('#testh6').append($(this).parents("tr").find("h6").clone());
});

編集:コメントへの回答:

val == 0 のときに再度削除するには

$('input').keyup( function () {
    if ($(this).val() > '0') {
        $('#testh6 h6').remove();  // Make sure there's no previous tag left.
        $('#testh6').append($(this).parents("tr").find("h6").clone());
    }
    elseif ($(this).val() == '0'){
        $('#testh6 h6').remove();
    }
});

もちろん、これはそのdivのすべてのh6タグを削除します。それが必要でない場合は、参照を保持するか、何らかの形で識別して後で回復できるようにする必要があります

于 2013-04-15T12:16:58.170 に答える