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

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀