我正在處理專案并遇到問題:當我單擊例如 //website/manageuser.php 上的按鈕時,我想要 //website/edituser.php 中按鈕的值
我嘗試<value>在按鈕中使用標簽但失敗了。我無法設法通過檔案轉移價值。
我的 manageuser.php 看起來像這樣:

在我按下例如“洗掉”按鈕后,我被轉發到 /deleteuser.php,我想在其中列印按鈕后面的值。不幸的是,它不適用于 StackOverflow Javascript 腳本。
我的 /deleteuser.php 的影像:

manageuser.php重要部分的代碼:
<table>
<tr>
<?php
$query = "select * from users";
$records = mysqli_query($con, $query);
while($data = mysqli_fetch_array($records))
{
?>
<th>
<p/>
<?php
print($data["full_name"]);
?>
<button type="button" value=" <?php print($data['full_name']) ?>" onclick="window.location.href='./edituser.php'">Edit</button>
<button type="button" onclick="window.location.href='./deleteuser.php'"> Delete </button>
</th>
<?php
}
?>
</tr>
</table>
deleteuser.php重要部分的代碼:
<!DOCTYPE html>
<html>
<body>
<script>
var str1 = document.getElementById("btn").innerHTML;
var str2 = document.getElementById("btn").value;
document.write("Button text: " str1);
document.write("<br>Button value: " str2);
</script>
</body>
</html>
uj5u.com熱心網友回復:
你不需要這個值。只需將值 from$data作為查詢引數附加到 URL。
<button type="button" onclick="window.location.href='./deleteuser.php?id=<?php echo $data['id'] ?>"> Delete </button>
然后在deleteuser.php你可以使用$_GET['id'].
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/437542.html
標籤:javascript php html
