Py学习  »  Jquery

如何在jquery上直接添加数字顺序

Amir • 5 年前 • 1397 次点击  

我被告知在表上添加一个数字顺序,但是当你添加一个表时,它从零开始计数,然后你删除这个表,它抛出一个动态顺序,而不是3-5(如果我删除4),我的意思是它应该保持顺序表1-2-3-4-5,我有一个大的代码,而不是w我想把它放在这里。只是我有功能

$('td.form_id').each(function(i) {
  $(this).text(i + 1);
});

我想把它用在我的工作上。

关于我的函数,我有一个隐藏id的表,当我单击它时,它显示了table

<table id="tablo">
  <thead>
    <tr>
      <th></th>
      <th id="tab">Name</th>
      <th id="tab">surname</th>
      <th id="tab">string</th>

      <td>
        <input style="background-color:green; color: white; width: 135px" type="button" class="add" value="Əlavə+">
      </td>

    </tr>
    <tr hidden class="form_id">
      <td>
        <input type="text" style='width:250px'>
      </td>
      <td>
        <input type="text" style='width:250px'>
      </td>
      <td>
        <input type="text" style='width:250px'>
      </td>
      <td>
        <span><a class='fa fa-edit save' style='margin-left:30px' href='javascript: void(0);'>saxla</a></span>
      </td>
    </tr>
  </thead>
  <tbody>
    <tr>

    </tr>
  </tbody>

还有一个函数,它每次都会出现一个表,并附加如下内容

$(document).ready(function() {

  $(".add").click(function() {

    //$("#td").show();
    var value = "<tr><td class='form_id' style='width:20px' >" + i + "</td><td  style='width:250px'><input type='text'  style='width:250px'></td><td  style='width:250px'><input type='text'  style='width:250px'></td><td  style='width:250px'><input type='text'  style='width:250px'></td><td><span ><a class='fa fa-edit save' style='margin-left:30px' href='javascript: void(0);'>saxla</a></span><span class='delete' style='margin-left:30px'><a class='glyphicon glyphicon-trash'href='javascript: void(0);'>delete</a></span></td>";
    $("table tbody").append(value);

  });
});
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/41277
 
1397 次点击  
文章 [ 1 ]  |  最新文章 5 年前