javascript - 如何存储按钮单击事件后从 PHP 动态传递到 JavaScript 的表数据的值?
问题描述
我一直在尝试在 HTML 表中的 1 对 1 聊天应用程序中列出用户,并在 PHP 中通过名称 ID 动态地唯一定义每个表单元格数据。问题是即使在 PHP 中传递名称值后,我也无法在单击该特定记录的按钮后检索相同的表格单元格值。
<?php
include("functions.php");
$token = $user_details[5];
// Get all Users except the Logged user
$users_list = get_users_list($user_details[2]);
?>
<table class="table">
<thead class="thead-style">
<tr>
<td class="text-center">Users List</td>
<td class="text-center">Login Status</td>
<td class="text-center"></td>
</tr>
</thead>
<tbody>
<?php
while($fetch = mysqli_fetch_assoc($users_list))
{
?>
<tr class="table-row-users">
<td class="text-center" id="<?php echo $fetch['user_name']; ?>" value="<?php echo $fetch['user_name']; ?>">
<?php echo $fetch['user_name']; ?></td>
<td class="text-center"><?php echo $fetch['user_login_status']; ?></td>
<td class="text-center"><button class="btn btn-outline-primary receiver_email='<?php echo base64_encode($fetch["user_email"]);?>'" id="single_chat" onclick='setReceiver("<?php echo $fetch['user_name']; ?>")'>Chat</button></td>
</tr>
<?php
}
?>
</tbody>
</table>
JavaScript 代码
function setReceiver(receiver_name)
{
var to_user_name = document.getElementById(receiver_name).value;//Unable to Retrieve the Value here
console.log(to_user_name);
//$('.receiver').append(to_user_name);
}
我正面临 JS 方面的错误。这也是我关于 Stack Overflow 的第一个问题。
解决方案
推荐阅读
- android - 每 x 个项目向 RecyclerView 添加广告
- django - 如何在 django 中提供图像?
- angular - 如何从组件初始化服务?
- wpf - Telerik WPF - TreeMap 以编程方式选择项目
- excel - vba 索引与多个条件匹配
- business-intelligence - obiee 11g 目录清理
- r - 逐页从网页中提取表格
- spring-security - 使用 Spring WebSocket 和安全性进行多房间授权
- c++ - 如何让 CMake 使用库的 -l 选项而不是由 cmake_find_package 创建的 IMPORTED 包的完整路径名?
- elasticsearch - 验证我对 elasticsearch 中 Dismax 查询的理解