0

在ajax代码的成功函数被触发后,我需要重写html代码,但是我没有任何id或类来识别元素,只能得到一个$(this).

在我的html中我有(我只能自定义div的内容。我不想写一个类,因为要修改的记录很多,结构复杂。):

<div class="jtable-input jtable-custom-input">
    <a onclick="ReWriteInputControl(' + data.record.Codigo + ', $(this))">Delete File</a>
</div>

在我的 javascript 中:

function ReWriteInputControl(code, container) {
    //here I can get the parent, etc.
    //$(container).parent().empty().append('<input type="file" onchange="this.form.submit()" name="myFile"/>') works

    var $parentContainer = $(container);

    $.ajax({
        url: "RemoveFileFromTeacher",
        data: { id: code },
        success: function (data) {
            if (data) {
                //Here I need to do
                //$(container).parent().empty().append('<input type="file" onchange="this.form.submit()" name="myFile"/>') but don't work
                //$parentContainer also didn't work
            }
            else {
            }
        },
        type: "POST",
        dataType: "json"
    });
}

在成功函数中,我需要做什么才能访问容器变量。

非常感谢。

4

0 回答 0