我正在寻找一种在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库。
有可能吗?
答案 0 :(得分:0)
一种解决方案是使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;
}