我是django的新手,当用户单击弹出窗口中的确认按钮时,我尝试运行脚本。该按钮位于一个表内,该表包含各种信息,包括我想传递给脚本的ID。
我也不希望脚本重新加载新页面。
这是index.html
文件中的表格
{% for st in scrapestats %}
<tr>
<td class="text-left">{{st.market}}</td>
<td>{{st.start|date:"Y-m-d H:i:s"}}</td>
<td>{{st.end|date:"Y-m-d H:i:s"}}</td>
<td>{{st.finished_count}}/{{st.total_count}}</td>
<td><a href="#"><span class="badge">{{st.ads}}</span></a></td>
<td><a href="#"><span class="badge">{{st.ads_feedback}}</span></a></td>
<td><a href="#"><span class="badge">{{st.user}}</span></a></td>
<td><a href="#"><span class="badge">{{st.seller_feedback}}</span></a></td>
<td><button type="button" name={{st.process_id}} class="btn btn-danger btn-xs confirm" data-toggle="modal" data-target="#Modal-{{st.process_id}}">
Revert
</button>
<!-- Modal -->
<div class="modal fade" id="Modal-{{st.process_id}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" align='left' id="delete-server-{{st.process_id}}">Are you sure you want to delete process id {{st.process_id}} ?</h5>
</div>
<div class="modal-body" align='left'>
This might be dangerous !
</div>
<div class="modal-footer">
<!-- <form action="#" method="POST" id="call_delete_server"> -->
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" id="confirm_deletion" data-id={{st.process_id}} class="btn btn-primary">Delete</button>
<!-- </form> -->
</div>
</div>
</div>
</div>
</tr>
{% endfor %}
还有脚本,也在index.html
<script>
$("#confirm_deletion").click(function (e) {
console.log($(this).attr("data-id"));
});
</script>
发生的事情是,当我单击{% for st in scrapestats %}
循环中的最后一个按钮时,它正确地输出了id,但是在其他任何按钮上,它均未输出任何东西。