使用php在ahref中发送LocalStorage

我正在寻找一种在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库。


如果可能的话,这可能吗?


守候你守候我
浏览 155回答 1
1回答

慕虎7371278

一种解决方案是使javascript重定向用户。因此,您可以为每个a元素分配一个onClick eventHandler 。并且处理程序函数将是这样的function handleLinkClick (e) {e.preventDefault ();&nbsp;//so we can do stuff before the user leaves the page&nbsp;const id = e.target.href.split ("?").pop ();//just extracting the id&nbsp;localStorage.setItem ("myKey", id);window.location.href = e.target.href;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript