如何将数据ID变量从模式传递到php页面 [英] How to pass data-id variable from modal to php page
问题描述
我有以下DELETE按钮,我通过数据ID传递了$ userid
I have the following DELETE button that I am passing $userid through the data-id
<a href='#myModal' class='trash' data-id='".$userid."' role='button'data-toggle='modal'>
Delete</a>
我有以下模态
<div class="modal fade" id="myModal" 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 <b><i class="title"></i></b> record, this procedure is irreversible.</p>
<p>Do you want to proceed?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<a href="#" class="btn btn-danger" id="modalDelete">Delete</a>
</div>
</div>
</div>
</div>
后面的JS获得DELETE按钮的值
And the following JS which gets the value of the DELETE button
$('.trash').click(function(){
var id=$(this).data('id');
$('#modalDelete').attr('href','delete_user.php?id=' + id);
});
我试图在模式中设置"href"的值,以便可以将其传递到名为delete_user.php的php页面,该页面将从数据库中删除用户.有人看到我要去哪里了吗?我无法获得href转到delete_user.php
I am trying to set the value of the "href" in the modal so that it can be passed to a php page called delete_user.php which deletes the user from the database. Anyone see where I am going wrong? I cannot get the href to go to the delete_user.php
推荐答案
您在这里遇到的错误data-id='".$userid."'
应该为data-id='<?php echo $userid;>'
you have mistake here data-id='".$userid."'
should be data-id='<?php echo $userid;>'
<a href='#myModal' class='trash' data-id='<?php echo $userid;>' role='button'data-toggle='modal'>
Delete</a>
为了获得更好的方法,请摆脱click
函数,使用模式事件和让引导程序处理其余部分
and for better approach, get rid of click
function, use modal event and let bootstrap handle the rest
$(document).ready(function() {
$('#myModal').on('show.bs.modal', function(e) {
var id = $(e.relatedTarget).data('id');
alert(id);
$('#modalDelete').attr('href', 'delete_user.php?id=' + id);
});
});
这篇关于如何将数据ID变量从模式传递到php页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!