【问题标题】:Copying values from a table row to a modal将值从表行复制到模式
【发布时间】:2013-05-28 16:00:32
【问题描述】:

我编写了一个 HTML 表格,显示来自 SQL 数据库的用户信息。

<table class="table table-hover">
    <tr>
        <th>Username</th>
        <th>Password</th>
        <th>Role</th>>
        <th>Attribute</th>
        </th>
        <th>Ideas/Score</th>
        <th>Edit</th>
        <th>Delete</th>
    </tr>
    <?php while($result=m ysqli_fetch_array($fetch)) { $usertoattrquery="SELECT * FROM usertoattr WHERE usertoattr.user_id=" .$result[user_id]; $attrfetch=mysqli_query($con,$usertoattrquery) or die ( 'could no connect with instructions'); echo "<tr><td>".$result[ "username"]. "</td><td>" .$result[ "password"]. "</td>
    <td>" .$result[ "role"]. "</td><td>only for Eval</td><td>coming soon</td><td>
         <a href='#editUser' role='button'  class='btn' data-toggle='modal'>Edit</a> </td>
         <td><button class='btn'onclick='deleteConfirm()'>Delete</button> </td></tr>"; } ?>
</table>

当有人按下特定行中的“编辑”按钮时,我希望打开一个模态框,并在模态框内复制此表行中的值(例如名称和密码)。

<div id="editUser" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    </div>
     <h3 id="myModalLabel">Edit User</h3>
User Name
    <input type="text">
    <br>User Password
    <input type="text">
    <br>User Role
    <select>
        <option>Evaluator</option>
        <option>Observer</option>
    </select>
    <br>User Attribute
    <select multiple>
        <option>Economics</option>
        <option>Software</option>
        <option>Management</option>
    </select>
    <br>
    <button class='btn btn-primary'>OK</button>
    <button class='btn' data-dismiss="modal" aria-hidden="true">Cancel</button>
</div>

这怎么可能?

【问题讨论】:

  • 我认为你应该看看 javascript 来做到这一点

标签: php html html-table modal-dialog


【解决方案1】:

您可以为每个&lt;td&gt; 添加一个 id(只要确保每个都不同,多个 id 都不好!!)

然后让您的 javascript 使用该值 (.innerHTML) 在模态框内设置输入文本的值。

【讨论】:

    猜你喜欢
    • 2016-11-24
    • 2013-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多