第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 Jquery 添加和刪除表行

使用 Jquery 添加和刪除表行

慕蓋茨4494581 2023-10-24 17:38:03
快完成了,但我不知道為什么它沒有按照預(yù)期的方式工作。功能很簡單,只需單擊最后一行即可添加一行,然后單擊左側(cè)的按鈕即可刪除一行。添加工作正常,刪除也可以,但是當(dāng)您刪除最后一行時(shí),您無法再次添加。你們能幫我嗎?這是代碼:$(document).ready(function() {  //Add Button  $(".fa-plus").click(function() {    var idTable = $(this).closest('table').attr('id');    $('#' + idTable + ' tbody>tr:last').clone(true).insertAfter('#' + idTable + ' tbody>tr:last');    //$('#' + idTable + ' tbody>tr:last #name').val('');    $(this).replaceWith('');    return false;  });  //Delete Butotn  $(".fa-trash").click(function() {    var idTable = $(this).closest('table').attr('id');    var rowCount = $('#' + idTable + ' tr').length;    if (rowCount > 2) {      // If is the last Row      if (!$(this).closest('tr').next().length) {        $(this).closest("tr").remove();        $('#' + idTable + ' tbody>tr:last #add').append("<i class='fa fa-plus fa-lg text-primary'></i>");      } else {        $(this).closest("tr").remove();      }    } else {      alert('Dont delete the only row');    }  });});<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" rel="stylesheet"/><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><table id="tbl_PilotOption" class="table table-bordered table-striped" style=" width: 100%;">  <thead>    <tr>      <th style="width:46px;"></th>      <th></th>      <th style="width: 35%;"></th>      <th style="width:46px;"></th>    </tr>  </thead>  <tbody>    <tr>      <td class="text-center" width="30px"><a id="delete"><i class="fa fa-trash ml-2"></i></a></td>      <td><input class="form-control" /></td>      <td><input class="form-control" /></td>      <td><a href="#" id="add"><i class="fa fa-plus fa-lg text-primary"></i></a></td>    </tr>  </tbody></table>
查看完整描述

1 回答

?
守候你守候我

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超10個(gè)贊

問題是,當(dāng)您刪除該行時(shí),您也刪除了單擊處理程序。所以而不是$(".fa-plus").click(function() {...使用$('table').on("click", ".fa-plus", function() {....


$(document).ready(function() {


  //Add Button

  $('table').on("click", ".fa-plus", function() {

    var idTable = $(this).closest('table').attr('id');

    $('#' + idTable + ' tbody>tr:last').clone(true).insertAfter('#' + idTable + ' tbody>tr:last');

    //$('#' + idTable + ' tbody>tr:last #name').val('');

    $(this).replaceWith('');

    return false;

  });


  //Delete Butotn

  $(".fa-trash").click(function() {

    var idTable = $(this).closest('table').attr('id');


    var rowCount = $('#' + idTable + ' tr').length;

    if (rowCount > 2) {

      // If is the last Row

      if (!$(this).closest('tr').next().length) {

        $(this).closest("tr").remove();

        $('#' + idTable + ' tbody>tr:last #add').append("<i class='fa fa-plus fa-lg text-primary'></i>");

      } else {

        $(this).closest("tr").remove();

      }

    } else {

      alert('Dont delete the only row');

    }



  });


});

<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css" rel="stylesheet"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<table id="tbl_PilotOption" class="table table-bordered table-striped" style=" width: 100%;">

  <thead>

    <tr>

      <th style="width:46px;"></th>

      <th></th>

      <th style="width: 35%;"></th>

      <th style="width:46px;"></th>

    </tr>

  </thead>

  <tbody>

    <tr>

      <td class="text-center" width="30px"><a id="delete"><i class="fa fa-trash ml-2"></i></a></td>

      <td><input class="form-control" /></td>

      <td><input class="form-control" /></td>

      <td><a href="#" id="add"><i class="fa fa-plus fa-lg text-primary"></i></a></td>

    </tr>


  </tbody>

</table>


查看完整回答
反對 回復(fù) 2023-10-24
  • 1 回答
  • 0 關(guān)注
  • 147 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)