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

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

刷新頁面后如何繼續將復選框保持在選中位置

刷新頁面后如何繼續將復選框保持在選中位置

慕容3067478 2022-01-01 20:01:05
我的 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>
查看完整描述

1 回答

?
阿波羅的戰車

TA貢獻1862條經驗 獲得超6個贊

利用 localStoragehttp://img1.sycdn.imooc.com//61d0429f00013c3204780666.jpg

對于 localstorage 將布爾值保存為 string 。這就是我們比較的原因 localStorage.getItem("box") == 'true'


$('input').prop('checked', localStorage.getItem("box") == 'true')


$('input').on('change', function() {

  window.localStorage.setItem($(this).attr('name'), Boolean($(this).is(':checked')))

})

http://img1.sycdn.imooc.com//61d042a000013c3204780666.jpg

查看完整回答
反對 回復 2022-01-01
  • 1 回答
  • 0 關注
  • 302 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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