将ID传递给jquery模态形式 [英] pass id to jquery modal form

查看:69
本文介绍了将ID传递给jquery模态形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下表,其中我显示数据库中的数据.当我单击编辑"按钮时,将出现一个对话框,我需要在数据库的文本框中显示数据.但是要从db获取数据,我需要模式中的player_id.

i have following table where i am showing data from database. when i click edit button a dialog appear, there i need to show data in text boxes from db. but for getting data from db i need player_id in modal from.

<td><?php echo $player_id ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $details; ?></td>
<td><button id="update_user">Edit</button></td>

所以在这里我想将player_id传递给jquery模态形式,在那里我可以基于该特定播放器的player_id从db获取数据,并在文本框中显示,然后再次更新为db.

so here i want to pass player_id to jquery modal form, where i can get data from db on the base of player_id for that specific player and show in text boxes and then again update to db.

<div id="update-form" title="Update Employee">

    <label for="id">ID</label>
    <input type="text" name="player_id" id="player_id" value="$player_id" />
    <label for="name">Name</label>
    <input type="text" name="name" id="name" value="$name"/>
          <label for="details">Details</label>
    <input type="text" name="details" id="details" value="$details"/>

我想将$ player_id变量传递给jquery模态形式.就是这样.

i want to pass $player_id variable to jquery Modal form. that's all.

推荐答案

尝试如下操作:

<td><?php echo $player_id ?></td>
<td><?php echo $name; ?></td>
<td><?php echo $details; ?></td>
<td>
    <button class="update_user" data-payer_id="<?php echo $player_id ?>">Edit</button>
</td>

<script>
$(".update_user").click(function(){
    var player_id = $(this).attr('data-payer_id');
    $("#update-form").find("#player_id").val(player_id);
    $("#update-form").dialog("open");
});
</script>

PS:player_id应该是对话框表单中的隐藏字段,除非它是可编辑的.

PS: player_id should be a hidden field in the dialog form unless it is editable.

这篇关于将ID传递给jquery模态形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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