【问题标题】:pass id to jquery modal form将 id 传递给 jquery 模态表单
【发布时间】:2012-02-08 17:08:06
【问题描述】:

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

<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。

<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 模态表单。就是这样。

【问题讨论】:

  • 如何显示模态表单?如果它是通过 ajax 加载的,$.post 将 id 写入您的 php 脚本,然后将其包含在表单中。
  • 点击编辑按钮时点击。模态表单打开
  • 能贴出打开模态表单的代码吗?
  • $( "#update-form" ).dialog({ autoOpen: false, height: 500, width: 450, modal: true, }); $( "#update_user" ) .button() .click(function() { $( "#update-form" ).dialog( "open" ); });
  • 你只显示一名球员吗?或者你桌上有多个玩家? (如果是后者,你应该使用 class="update_user" 而不是 id="update_user")

标签: php jquery


【解决方案1】:

试试这样的:

<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 应该是对话框表单中的隐藏字段,除非它是可编辑的。

【讨论】:

    猜你喜欢
    • 2014-03-09
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 2019-04-03
    • 1970-01-01
    • 1970-01-01
    • 2017-12-31
    • 2019-08-22
    相关资源
    最近更新 更多