2 回答

TA貢獻1843條經驗 獲得超7個贊
您可以添加AddToZip.php的代碼嗎?
您可以將所有id存儲到會話值中,并檢查fetch.php上的此數組中是否包含該 id 。
AddToZip.php:
session_start();
if (!isset($_SESSION['added_to_zip_ids']))
$_SESSION['added_to_zip_ids'] = [];
if (array_search($_GET['id'], $_SESSION['added_to_zip_ids']) === false)
$_SESSION['added_to_zip_ids'][] = $_GET['id'];
獲取.php:
<?php
...
session_start();
if (!isset($_SESSION['added_to_zip_ids']))
$_SESSION['added_to_zip_ids'] = [];
if(mysqli_num_rows($result) > 0)
{
$output .= '<h4 align = "center">Search Result</h4>';
$output .= '<div class="table-responsive">
<table class = "table table bordered">
<tr>
<th>ID</th>
</tr>';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["ID"].'</td>
<td><button '.(array_search($row["ID"], $_SESSION['added_to_zip_ids']) === false ? '' : 'disabled').' type="button" class="btn btn-primary" onclick="addToZip(\''.$row["ID"].'\', this)"><i class="fa fa-pdf" aria-hidden="true"> </i>Add to Zip</button></td>
</tr>
';
}
echo $output;
}
...
?>
要清除存儲的值,您有兩種解決方案:
保留其他會話數據
會話開始();
if (isset($_SESSION['added_to_zip_ids']))
unset($_SESSION['added_to_zip_ids']);清除一切
會話開始();
session_unset();
這些行可以位于服務器上的任何位置。

TA貢獻1798條經驗 獲得超7個贊
我建議使用事件處理程序“keyup”(就像您已經做的那樣)和/或“更改”處理程序來激活功能(例如 check_disable_status)
$('#search_text').keyup(check_disable_status) $('#search_text').change(check_disable_status)
并且您還應該在 DOM 的“就緒”狀態下啟動此函數。
在此函數中,您只需檢查字段的當前“狀態”,或者可能是業務邏輯的其他依賴項,并將字段始終設置為“啟用”或“禁用”狀態。
- 2 回答
- 0 關注
- 125 瀏覽
添加回答
舉報