我需要为Modal弹出窗口设置动态值。
这是我的模态
<!-- Modal -->
<div class="modal fade" id="popUpModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">"this is the value {{ cra }}"</h4>
</div>
<form class="modal-form" id="docsForm" action="{% url 'contact_delete' pk=contact.id %}" method="post" enctype="multipart/form-data">
<input type="file" name="upload" />
<input type="hidden" name="brandcode" value=this.id />
<input type="submit" /></form>
<div class="modal-footer">
</div>
</div>
</div>
</div>
这就是我正在尝试的
<script>
$('#popUpModal').on('show.bs.modal', function(e) {
var $modal = $(this),
esseyId = e.relatedTarget.id;
$modal.find('.modal-form').html(esseyId);
})
</script>
根据我想要的值记录
contact/delete/1
contact/delete/2
....
更新1
<a id="{{ contact.id }}" type="button" data-target="#popUpModal" class="btn btn-box-tool" data-toggle="modal" data-original-title="{% trans 'Update Doc' %}">
答案 0 :(得分:1)
这是我获得预期回复的方式
<script type="text/javascript">
$('#popUpModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var id= button.data('id') // Extract info from data-* attributes
var modal = $(this)
console.log(id)
$("#docsForm").attr("action", "/contact_delete/" + id+"/");
})
</script>