0

jqueryでthisオブジェクトを使用して親要素を実現するにはどうすればよいですか。$.post私が見たものは、それをログに記録すると、リクエストの詳細$(this)に関する情報が得られます。またはオブジェクトPOSTを使用して、最も近い要素または親要素をどのように達成できますか。thisany element

thisがリクエストのオブジェクトであることを知ったPOSTので、リクエストの詳細を取得します。

HTML

<table>
<tr>
    <td><span class="remove-file-confirm" id="aa" file-name="whatsup"></span></td>
</tr>
<tr>
    <td><span class="remove-file-confirm" id="bb" file-name="gotstuck"></span></td>
</tr>
</table>

脚本

$(".remove-file-confirm").click(function(){

    var rconfirm = confirm("Are you sure, want to delete this file");

    if (rconfirm) {
        var rfileid = $(this).attr("id");
        var rfilecode = $(this).attr("file-name");

        $.post("ajx_delete_file.php", {fid:rfileid, fcd:rfilecode}, function(return_datad){
            if (return_datad == "good") {
                var k = $(this);
                //$(this).closest("<tr>").hide();
                console.log(k); // show information on post request
                // how can i achieve .remove-file-confirm nearest tr element
            } else {
                alert("Cannot delete this file");
                console.log(return_datad);
            }
        });

    }

});
4

2 に答える 2

2

これを試して

$('#'+rfileid).closest("tr").hide();
于 2013-06-23T08:41:14.460 に答える
2

このように要素のスコープ内にある場合は、要素を事前に割り当てることができます。

実行する前に変数を割り当てますpost

var $parent = $(this).closest("tr")

次に、 post 内で使用します。

$parent.hide();

完全なコード:

$(".remove-file-confirm").click(function(){

    var rconfirm = confirm("Are you sure, want to delete this file");
    var $parent = $(this).closest("<tr>")
    if (rconfirm) {
        var rfileid = $(this).attr("id");
        var rfilecode = $(this).attr("file-name");

        $.post("ajx_delete_file.php", {fid:rfileid, fcd:rfilecode}, function(return_datad){
            if (return_datad == "good") {
                $parent.hide();
                //$(this).closest("<tr>").hide();
                console.log(k); // show information on post request
                // how can i achieve .remove-file-confirm nearest tr element
            } else {
                alert("Cannot delete this file");
                console.log(return_datad);
            }
        });

    }

});
于 2013-06-23T08:42:18.423 に答える