为了账号安全,请及时绑定邮箱和手机立即绑定

使用php在ahref中发送LocalStorage

使用php在ahref中发送LocalStorage

守候你守候我 2021-05-06 13:13:02
我正在寻找一种在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;

}


查看完整回答
反对 回复 2021-05-27
  • 1 回答
  • 0 关注
  • 152 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信