如何将数据ID变量从模式传递到php页面 [英] How to pass data-id variable from modal to php page

查看:68
本文介绍了如何将数据ID变量从模式传递到php页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆