关闭按钮上的javascript问题|如何解决?

关闭按钮上的javascript问题|如何解决?,javascript,jquery,laravel-6,Javascript,Jquery,Laravel 6,这里javascript用于创建多个表字段,从单击一个加号按钮开始多次打开。现在它工作正常。我的问题是,当我在java脚本$(this.parent().parent())中使用时,当我单击关闭按钮时,它将被删除,但不会被删除。当我使用$('tbody').remove()或$('tbody tr').remove()或$('tbody tr td').remove()然后删除整个表及其字段…请让 我认识任何人…我怎么能解决它 $('#addRow').on('click', function(

这里javascript用于创建多个表字段,从单击一个加号按钮开始多次打开。现在它工作正常。我的问题是,当我在java脚本$(this.parent().parent())中使用时,当我单击关闭按钮时,它将被删除,但不会被删除。当我使用
$('tbody').remove()
$('tbody tr').remove()
$('tbody tr td').remove()
然后删除整个表及其字段…请让

我认识任何人…我怎么能解决它

$('#addRow').on('click', function() {
    addRow();
});

function addRow() {

    var td1 = '<td>' +
        '<label class="control-label">Class / Field :</label>' +
        '</td>' +
        '<td>' +
        '<input class="form-control" id="idSource" type="text" name="class[]" />' +
        '</td>' +
        '<td>' +
        '<label class="control-label">University :</label>' +
        '</td>' +
        '<td>' +
        '<input class="form-control" id="idDestination" type="text" name="university[]" />' +
        '</td>';
    var td2 = '<td>' +
        '<label class="control-label">Institute / Collage Name :</label>' +
        '</td>' +
        '<td>' +
        '<input class="form-control" id="idSource" type="text" name="institute_name[]" />' +
        '</td>' +
        '<td>' +
        '<label class="control-label"> Percentage / GPA / CGPA : </label>' +
        '</td>' +
        '<td>' +
        '<input class="form-control" id="idDestination" type="text" placeholder="00.00" name="per[]"/>' +
        '</td>';
    var td3 = '<td>' +
        '<label class="control-label">Start Date :</label>' +
        '</td>' +
        '<td>' +
        '<input class="form-control" id="idSource" type="date" name="sdate[]" />' +
        '</td>' +
        '<td>' +
        '<label class="control-label">End Date:</label>' +
        '</td>' +
        '<td>' +
        '<input class="form-control" id="idDestination" type="date" name="edate[]" />' +
        '</td>';
    var td4 = '<td><a class="btn btn-danger" id="remove"><i class="fa fa-remove"></i></a></td>';

    var td5 = '<td>' +
        '<b>&nbsp;</a>' +
        '</td>' +
        ' <td>' +
        '<b>&nbsp;</b>' +
        '</td>' +
        ' <td>' +
        '<b>&nbsp;</b>' +
        '</td>' +
        ' <td style="text-align: right;">' +
        '<b><a class="btn btn-danger" id="remove"><i class="fa fa-remove"></i></a></b>' +
        '</td>';

    $('tbody').append('<tr>' + td1 + '</tr>' + '<tr>' + td2 + '</tr>' + '<tr>' + td3 + '</tr>' + '<tr>' + td5 + '</tr>');
};

$('tbody').on('click', '#remove', function() {
    var last = $('tbody').length;
    if (last == 1) {
        alert('You Can Not Remove Last');
    } else {
        if (confirm("Do you want to delete this row?")) {
            $(this).parent().parent().remove();
            $('tbody').remove();
        }
    }
});
$('addRow')。在('click',function()上{
addRow();
});
函数addRow(){
变量td1=''+
'类别/字段:'+
'' +
'' +
'' +
'' +
'' +
“大学:”+
'' +
'' +
'' +
'';
变量td2=''+
'学院/学院名称:'+
'' +
'' +
'' +
'' +
'' +
'百分比/GPA/CGPA:'+
'' +
'' +
'' +
'';
变量td3=''+
'开始日期:'+
'' +
'' +
'' +
'' +
'' +
'结束日期:'+
'' +
'' +
'' +
'';
var td4='';
变量td5=''+
' ' +
'' +
' ' +
' ' +
'' +
' ' +
' ' +
'' +
' ' +
'' +
'';
$('tbody')。追加(''+td1+''+''+td2+''+''+td3+''+td5+'');
};
$('tbody')。在('click','#remove',函数()上{
var last=$('tbody')。长度;
如果(最后==1){
警报(“您不能删除最后一个”);
}否则{
如果(确认(“是否要删除此行?”){
$(this.parent().parent().remove();
$('tbody').remove();
}
}
});
刃锉

 <div class="col-md-12 field-wrapper" id="wrapper">
                        <div class="panel panel-footer">
                        <form id="allInputsFormValidation" class="form-horizontal" action="{{route('create_education')}}" method="post">
                                @csrf
                            <table class="table table-striped col-md-12">
                                <thead>
                                    <tr>

                                        <td><b>
                                            <a class="btn btn-success" id="addRow"><i class="fa fa-plus"></i></a>
                                        </td>
                                        <td><b>&nbsp;</b></td>
                                        <td><b>&nbsp;</b></td>
                                        <td><b>

                                        </td>

                                    </tr>
                                </thead>
                                <div class="form-group column-sizing">
                                <tbody id="tbody">
                                    <tr>
                                        <td>
                                            <label class="control-label">Class / Field :</label>
                                        </td>
                                        <td>
                                            <input class="form-control" type="text" name="class[]" />

                                        </td>
                                        <td>
                                            <label class="control-label">University :</label>
                                        </td>
                                        <td>
                                            <input class="form-control" type="text" name="university[]" />
                                        </td>                               
                                    </tr>
                                    <tr>
                                        <td>
                                            <label class="control-label">Institute / Collage Name :</label>
                                        </td>
                                        <td>
                                            <input class="form-control" type="text" name="institute_name[]" />
                                        </td>
                                        <td>
                                            <label class="control-label">Percentage / GPA / CGPA / SPI :</label>
                                        </td>
                                        <td>
                                            <input class="form-control" type="text" name="per[]" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <label class="control-label">Start Date :</label>
                                        </td>
                                        <td>
                                            <input class="form-control" type="date" name="sdate[]" />
                                        </td>
                                        <td>
                                            <label class="control-label">End Date :</label>
                                        </td>
                                        <td>
                                            <input class="form-control" type="date" name="edate[]" />
                                        </td>

                                    </tr>
                                     <tr>

                                         <td><b>&nbsp;</b></td>
                                        <td><b>&nbsp;</b></td>
                                        <td><b>&nbsp;</b></td>
                                        <td style="text-align: right;"><b>
                                            <a class="btn btn-danger" id="remove"><i class="fa fa-remove"></i></a></b>
                                        </td>

                                    </tr>

                                </tbody>
                                </div>
                            </table>  
                            <div class="card-footer" style="margin-left: 90%">
                                <button type="submit" class="btn btn-info btn-fill">Submit</button>
                            </div>  
                        </form>
                        </div>
                     </div> 

@csrf
类别/字段:
大学:
学院/学院名称:
百分比/GPA/CGPA/SPI:
开始日期:
结束日期:
提交
以下是新方法,我希望它能满足您的需要。 按下面的“运行代码片段”按钮
$('#data')。在('click','.remove record',({currentTarget:elRemove})上=>{
var isLastRecord=$('.data record')。长度===1;
如果(isLastRecord){
警报(“您不能删除最后一个”);
}else if(确认('you want delete this row?')){
$(elRemove).closest('.data record').remove();
}
});
$('#添加新记录')。在('单击',()=>$('#数据')。追加(`
类别/字段:
大学:
学院/学院名称:
百分比/GPA/CGPA:
开始日期:
结束日期:
`));

以下是新方法,我希望它能满足您的需要。 按下面的“运行代码片段”按钮
$('#data')。在('click','.remove record',({currentTarget:elRemove})上=>{
var isLastRecord=$(')。数据记录