简体   繁体   English

将值从php生成的表传递给模式

[英]Passing values from a php generated table to modal

I got a table generated in PHP: 我得到了用PHP生成的表:

<tbody>
<?php
    $results = DB::select()->from('users')->execute();
    foreach ($results as $user) {
        echo "<tr id='".$user['id']."'>
        <input type=\"hidden\" id='userNameHidden' value='".$user['username']."'>
        <input type=\"hidden\" id='userEmailHidden' value='".$user['email']."'>
        <td class='username'>".$user['username']."</td><td class='email'>".$user['email']."</td><td class='lastlogin'>".date('d/m/Y',$user['last_login'])."</td><td class='logins'>".$user['logins']."</td><td><a class='editThis'><i class=\"small material-icons\">mode_edit</i></a> <a href='#deleteUser' class='deleteThis'><i class=\"small material-icons\">delete</i></a> </td></tr>";

    }
?>

My question is, how to make the edit/delete buttons work on a modal that is opened on the same site? 我的问题是,如何使编辑/删除按钮在同一站点上打开的模式下起作用? I just want to pass values from <td> to <input type="text"> on the modal. 我只想将值从<td>传递到模态上的<input type="text">

You can send it with GET or POST method to another php file and than work with them there. 您可以使用GETPOST方法将其发送到另一个php文件,然后在此处使用它们。 If you want to work on the same page you can get it via JavaScript: 如果要在同一页面上工作,可以通过JavaScript进行获取:

var value = document.getElementById ( "userNameHidden" ).innerText;

After that: 之后:

document.getElementById ( "inputid" ).value = value;

If you would like to create a login system definately use POST or GET (not recommended) to pass the values. 如果您想创建一个登录系统,一定要使用POST或GET(不推荐)来传递值。

If you want it to happen with a button click. 如果您希望通过按钮进行操作,请单击。 You can make a funcion and a button to go with it: 您可以创建一个功能和一个按钮来配合使用:

<button onclick="delete()">Delete</button>

And the js: 和js:

function delete(){
var value = document.getElementById ( "userNameHidden" ).innerText;
document.getElementById ( "inputid" ).value = value;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM