在两个不同的表中添加删除行

时间:2018-10-25 19:54:53

标签: php jquery html

仅在表ID不同的情况下,行才被添加到上部表中 该功能可以正常工作,因为我为不同的表包含了不同的ID 请heklpme找出错误 JS在下面

$(document).ready(function () {
    $('#myTable').on('click', 'input[type="button"]', function () {
        $(this).closest('tr').remove();
    });
    $('p input[type="button"]').click(function () {
        $('#myTable').append('<tr><td><input type="text" class="form-control"  name="aname[]" value="" placeholder="Input Name" /> </td><td><input type="amount" class="form-control" name="aamount[]" value="" placeholder="Input Value" /></td><td><input type="number" class="form-control" name="apriority[]" value="" placeholder="Input Value" /></td><td><input type="button" class ="btn btn-danger" value="x Delete" /></td></tr>')
    });
    $('#myTable1').on('click', 'input[type="button"]', function () {
        $(this).closest('tr').remove();
    });
    $('p input[type="button"]').click(function () {
        $('#myTable1').append('<tr><td><input type="text" class="form-control"  name="dname[]" value="" placeholder="Input Name" /> </td><td><input type="amount" class="form-control" name="damount[]" value="" placeholder="Input Value" /></td><td><input type="number" class="form-control" name="dpriority[]" value="" placeholder="Input Value" /></td><td><input type="button" class ="btn btn-danger" value="x Delete" /></td></tr>')
    });
});

下面是HTML

<div class="form-group">
    <label for="grade">Grade</label>
   <select class="form-control required alphanum"  name="grade" id="grade" required>
    <option value="">Please select...</option>
    <?php fetch_grade($conn);
    ?>
</select>
</div>                    
<div class="form-group">
    <label for="name">Basic Salary</label>
    <input type="text" name="basic" id="basic"  class="form-control" /> 
</div>
 <div class="form-group">
    <label for="overtime">Overtime Rate(Per Hour)</label>
    <input type="text" name="overtime" id="overtime"  class="form-control" /> 
</div>

Allowances 
            <br>
             <p> <input type="button" class="btn btn-primary" value="+ Add Allowance"></p>
        <table id="myTable" class="table table-condensed table-hover table-bordered table-hover table-responsive table-striped">
            <thead>
                <tr>
                    <th>Allowance Name</th>
                    <th>Amount</th>
                    <th>Display Priority</th>
                </tr>
            </thead>
            <tbody>
            <tr>
                <td><input type="text" class="form-control"  name="aname[]" value="" placeholder="Input Name" /> </td>
                <td><input type="amount" class="form-control" name="aamount[]" value="" placeholder="Input Value" /></td>
                <td><input type="number" class="form-control" name="apriority[]" value="" placeholder="Input Value" /></td>
               <td><input type="button" class ="btn btn-danger" value="x Delete" /></td>
            </tr>
          </tbody>
        </table>

 Deductions 
            <p> <input type="button" class="btn btn-primary" value="+ Add Deduction"></p>
        <table id="myTable1" class="table table-condensed table-hover table-bordered table-hover table-responsive table-striped">
            <thead>
                <tr>
                    <th>Deduction Name</th>
                    <th>Amount</th>
                    <th>Display Priority</th>
                </tr>
            </thead>
            <tbody>
            <tr>
                <td><input type="text" class="form-control"  name="dname[]" value="" placeholder="Input Name" /> </td>
                <td><input type="amount" class="form-control" name="damount[]" value="" placeholder="Input Value" /></td>
                <td><input type="number" class="form-control" name="dpriority[]" value="" placeholder="Input Value" /></td>
               <td><input type="button" class ="btn btn-danger" value="x Delete" /></td>
            </tr>
          </tbody>
        </table>

我不确定我要去哪里错了?我搜索了各种论坛,但没有提供准确的解决方案,并且想知道是否有人可以对此进行讨论,我该如何选择呢?

1 个答案:

答案 0 :(得分:1)

此选择器两次绑定某些功能:

class func new(_ eid: String) {
    //Create Animal Entity
    let container = CoreDataService.persistentContainer
    container.performBackgroundTask { (context) in
        let mo = Animal(context: context)
        mo.eid = eid
        mo.lastModified = Date()
        mo.purchaseDate = Date()
        mo.uuid = UUID()

        do {
            try context.save()
        }
        catch let error {
            print(error)
        }
    }
}

这意味着它只会在一张表上运行。

Animal.new(eid) { (animal) in if let animal = animal { } 元素中添加一些类

$('p input[type="button"]')

并绑定到它:

<p>