亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用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 關注
  • 185 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號