【问题标题】:How to get row value from table when delete button is clicked?单击删除按钮时如何从表中获取行值?
【发布时间】:2022-01-11 09:45:10
【问题描述】:

单击删除按钮时,我正在尝试删除行。

<tbody>
  {% for dt in data %}
  <tr>
    <td>
      <i class="fa fa-external-link user-profile-icon"></i>
      <a href="{{dt.url}}" target="_blank">{{dt.url}}</a>
    </td>
    <td>{{dt.modified}}</td>
    <td>
      <button type="button" class="fa fa-trash-o btn btn-danger" data-toggle="modal" data-target="#exampleModal{{forloop.counter}}">Delete</button>
    </td>
    <div class="modal fade bd-example-modal-lg" id="exampleModal{{forloop.counter}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModal{{forloop.counter}}">DELETE</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <p>
              Are you sure you want to delete this row
            </p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
            <button type="submit" class="btn btn-primary">Yes</button>
          </div>
        </div>
      </div>
    </div>
  </tr>
  {% endfor %}
</tbody>


当我单击删除按钮时,会出现确认模式,当我单击是时,我必须发送 {{dt.url}} 以获取相应的删除按钮。 我可以使用隐藏类型的输入标签并使用 {{dt.url}} 设置输入值。我无法检查单击了哪个删除按钮。请帮忙。

【问题讨论】:

    标签: javascript html jquery django


    【解决方案1】:

    在你的表外添加&lt;input type="hidden" name="deletefile" value="" id="deletefileID"&gt;

    现在将按钮的值设置为{{dt.url}

    <button type="button" value="{{dt.url}" class="fa fa-trash-o btn btn-danger" data-toggle="modal" data-target="#exampleModal{{forloop.counter}}">Delete</button>
    

    这是在点击删除按钮时使用这个值来设置隐藏输入标签的值。

    
    $('.btn-danger').on('click',function(){
           var tmp = this;
           tmp = tmp.value;
           $('#deletefileID').val(tmp);
    });
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-08
      相关资源
      最近更新 更多