我的 PHP、js 代碼有點問題。當我提交表單頁面正在重新加載但輸入復選框未處于選中模式時,但我需要的是。我想也許我需要從 URL 獲取參數,然后將它與 DOM 元素進行比較,然后為輸入設置檢查模式?PHP代碼:if(isset($_GET['user_id'])) { try { $PDO_connection = new PDO($dsn, $user, $password, $opt); $queryForUserInfo = "SELECT position, dateOfBirth, rank, tellNumber, worker_id FROM workers WHERE user_id = :id"; $sth = $PDO_connection->prepare($queryForUserInfo); $sth->bindParam(":id", $_GET['user_id'], PDO::PARAM_STR); $sth->execute(); $result = $sth->fetchAll(PDO::FETCH_ASSOC); $queryForComeAndReturnUserInfo = "SELECT date_come, date_return FROM outside_records WHERE worker_id = {$result[0]['worker_id']} ORDER BY date_return DESC"; $sth1 = $PDO_connection->prepare($queryForComeAndReturnUserInfo); $sth1->bindParam(":id", $_GET['user_id'], PDO::PARAM_STR); $sth1->execute(); $outsideSchedule = $sth1->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e){ echo $e->getMessage(); };}<form action="<?php echo $_SERVER['PHP_SELF']?>" method="get" id="listOfUsers_form"> <!--just for getting id to make db query--> <?php foreach ($AllUsers as $user):?> <tr class='usersList'> <td><input type='checkbox' name='user_id' value='<?php if(isset($user)){echo $user['user_id'];}?>'></td> <td><?php echo $user['name'];?></td> <td><?php echo $user['surname'];?></td> <td><?php echo $user['position'];?></td> </tr> <?php endforeach; ?></tbody></form>
刷新頁面后如何繼續將復選框保持在選中位置
慕容3067478
2022-01-01 20:01:05