我在将参数传递到模态窗口时遇到问题。我特别想传递一个按钮href,但似乎没有任何东西出现在我的模态中。
有人能指出我正确的方向吗?
的Javascript
<script>
$(document).ready(function() {
$('#confirm-delete').on('shown.bs.modal', function(event) {
$("#roomId").val($(event.relatedTarget).data('id'));
var roomId = $(e.relatedTarget).data('id');
$(e.currentTarget).find('input[name="roomId"]').val(roomId);
$('.url').html('Delete URL: <strong>' + $(this).find('.btn-danger').attr('href') + '</strong>');
});
});
</script>
模态
<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Confirm Delete</h4>
</div>
<div class="modal-body">
<p>You are about to delete. Do you want to proceed?</p>
<input type="text" name="roomId" value=""/>
<div class="url"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<a href="#" class="btn btn-danger danger">Delete</a>
</div>
</div>
</div>
链接到模态
<button data-href="/admin/rooms/delete/{{ $room->id }}" data-id="{{ $room->id}}" data-toggle="modal" data-target="#confirm-delete" href="#" type="button" class="btn btn-danger">Delete</button>
答案 0 :(得分:1)
我认为这就是你需要的
$(function(){
$('#confirm-delete').on('shown.bs.modal', function(e) {
var button = $(e.relatedTarget);
// this refers to Modal
$('input', this).val(button.data('id'));
$('.url', this).html('Delete URL: <strong>' + button.data('href') + '</strong>');
});
});