doupeng5320 2019-05-12 05:10
浏览 45
已采纳

使用php在href中发送本地存储

I am a looking for a way to set LocalStorage in A Href.

Here is the PHP code:

 <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>

On click of edit or view, I want to store "$row["id"];" to local storage? I need this in local storage because I am using js library which is looking for localstorage[key].

Is this possible if so how?

  • 写回答

1条回答 默认 最新

  • dsfdsfdsfdsf1223 2019-05-12 05:24
    关注

    A solution would be to make javascript redirects the user. So you can assign an onClick eventHandler to each a element. And the handler function would be something like this

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记