我正在寻找一种在Href中设置LocalStorage的方法。这是PHP代码: <table cellspacing="0"> <tr> <th>ID</th> <th>Name</th> <th>View</th> <th>Edit</th> </tr> <?php $count=1; $sel_query="Select * from userdetails ORDER BY id desc;"; $result = mysqli_query($con,$sel_query); while($row = mysqli_fetch_assoc($result)) { //something has to be done later. ?> <tr> <td align="center"><?php echo $count; ?> <td align="center"><?php echo $row["docname"]; ?> <td align="center"><a href="view.php?id=<?php echo $row["id"]; ?>">View</a></td> <td align="center"><a href="edit.php?id=<?php echo $row["id"]; ?>">Edit</a></td> </tr> <?php $count++; } ?> </table>单击编辑或查看后,我要存储“ $ row [“ id”];“ 到本地存储?我需要在本地存储中使用此文件,因为我正在使用正在寻找localstorage [key]的js库。如果可能的话,这可能吗?
1 回答

慕虎7371278
TA贡献1802条经验 获得超4个赞
一种解决方案是使javascript重定向用户。因此,您可以为每个a元素分配一个onClick eventHandler 。并且处理程序函数将是这样的
function handleLinkClick (e) {
e.preventDefault ();
//so we can do stuff before the user leaves the page
const id = e.target.href.split ("?").pop ();
//just extracting the id
localStorage.setItem ("myKey", id);
window.location.href = e.target.href;
}
添加回答
举报
0/150
提交
取消