<a href="#" data-target="#edit-order value="<?php echo $users[$i]['id']; ?>" name="delete-order" id="bb-confirm" data-placement="left" data-rel="tooltip" data-toggle="modal" data-original-title="Delete Order" class="btn btn-danger"><i class="fa fa-times icon-only"></i></a>
我想将“值”信息解析为此编辑订单表单,但我无法使其正常工作。我试过GET但没有尝试过。
<div class="modal fade modal-scroll" id="edit-order" 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"><i class="fa fa-plus-circle"></i> Add Order</h4>
</div>
<div class="modal-body padding-2x">
<form role="form" method="post">
<div class="form-group">
<label>Order ID #</label>
<?php echo ORDER-ID-PASSED-FROM-BUTTON; ?>
</div>
<div class="form-actions no-padding-bottom">
<div class="btn-group">
<button type="submit" name="edit-order" class="btn btn-primary">Update Order</button>
</div>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
有人可以帮我这个吗?非常感谢
答案 0 :(得分:0)
如果您的模态对话框保留在DOM中,您可以使用以下代码:
var links = document.querySelectorAll('[data-target="#edit-order"]');
[].forEach.call(links, function(link) {
link.onclick = function() {
var value = link.getAttribute('value');
var group = document.querySelector('.modal form .form-group');
var input = document.querySelector('.modal form .form-group input');
if (input) {
group.removeChild(input);
}
input = document.createElement('input');
input.setAttribute('value', value);
input.setAttribute('name', 'order');
group.appendChild(input);
};
});
或使用jQuery:
$('[data-target="#edit-order"]').click(function() {
$('.modal form .form-group input').remove();
var value = $(this).attr('value');
$('.modal form .form-group').append('<input name="order" value="' + value + '"/>');
});