【发布时间】:2019-06-09 22:16:03
【问题描述】:
我是 django 和 javascript 的新手,我尝试使用 rowid 的值打开模式,最后我可以传递值但无法在下面的代码中打开表单;
HTML 内部:
<thead>
{% for customer in object_list %}
<tr>
<td>{{ customer.id }}</td>
<td>{{ customer.name }}</td>
<td>{{ customer.surname }}</td>
<td>{{ customer.gender }}</td>
<td>{{ customer.email }}</td>
<td>{{ customer.phone }}</td>
<td>{{ customer.bloodtype }}</td>
<td><a href=# data-target="#my_modal" data-toggle="modal" class="identifyingClass" data-id="{{ customer.id }}">Open Modal</a> </td>
</tr>
{% endfor %}
</thead>
我的模态
<h2>Modal</h2>
<div class="modal fade" id="my_modal" tabindex="-1" role="dialog" aria-labelledby="my_modalLabel">
<div class="modal-dialog" role="dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal Title</h4>
</div>
<div class="modal-body">
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Update">
</form>
<input type="hidden" name="hiddenValue" id="hiddenValue" value="{{ customer.id }} />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
<button type="button" class="btn btn-primary">Yes</button>
</div>
</div>
</div>
Javascript
<script type="text/javascript">
$(function () {
$(".identifyingClass").click(function () {
var my_id_value = $(this).data('id');
$(".modal-body #hiddenValue").val(my_id_value);
})
});
</script>
【问题讨论】:
-
你在使用 boostrap 吗?
-
正常的html
标签: javascript django modal-dialog modalviewcontroller