Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
删除jquery中的tr元素_Jquery - Fatal编程技术网

删除jquery中的tr元素

删除jquery中的tr元素,jquery,Jquery,我有一个tr元素表,我在其中单击每一行的delete,它会从表中删除自己。我的html如下所示 <tr class="tr_body"> <td> <input type="text" class="fabric_input createWOBlockBG small ui-autocomplete-input" name="basefabrics[]" onfocus ="loadUniqueAjax(' . "'fabric_input'" .

我有一个tr元素表,我在其中单击每一行的delete,它会从表中删除自己。我的html如下所示

<tr class="tr_body">
    <td>
    <input type="text" class="fabric_input createWOBlockBG small ui-autocomplete-input" name="basefabrics[]" onfocus ="loadUniqueAjax(' . "'fabric_input'" . ')" autocomplete="off">
    </td>
    <td>
    <input type="text" class="fac_input createWOBlockBG small ui-autocomplete-input" name="facSnapshots[]" id="facSnapshot" autocomplete="off">
    </td>
    <td>
    <a class ="deleteRow">delete</a>
    </td>
</tr>
$('.deleteRow').click(function(){

    var elementDelete = $(this).parent().parent();
    $('#tablelist').remove(elementDelete);

});

但是,它返回一个未捕获的TypeError:当我单击deleteRow锚标记时,Object[Object Object]没有方法“replace”。提前感谢您的帮助。

尝试使用此功能

function removeTableRow(trId) {
$(document.getElementById(trId)).remove();
}
并通过调用此函数

removeTableRow( "tr_body" );

你可以这样做

$( document ).ready( function () {
    $( '#tablelist .deleteRow' ).click( function ( event ) {
        event.preventDefault();
        $( this ).closest( 'tr' ).remove();
    });
});
试试这个


只需删除元素本身

替换

$('#tablelist').remove(elementDelete);

检查这把小提琴

提及

要获得正确的语法,只需使用:-

$('.deleteRow').click(function(){
 $(this).parent().parent().remove();
});
实际上,您正试图使用remove作为本机javaScript样式,但在jquery中不需要找到父元素。Jquery将代表您这样做,因此您只需要指定要删除的元素

ParentElement.remove(childElement); //Javascript style

$(childElement).remove(); // Jquery

您是否检查了您的表是否具有良好的id表列表?此外,您可以使用elementDelete.remove直接删除TR元素,而不是使用表。请注意,TR不是表的直接子元素,因为您可能忘记了它们之间的TBODY元素。
elementDelete.remove();
$('.deleteRow').click(function(){
    var elementDelete = $(this).parent().parent();

    $(elementDelete).remove();

});
$('.deleteRow').click(function(){
 $(this).parent().parent().remove();
});
ParentElement.remove(childElement); //Javascript style

$(childElement).remove(); // Jquery