久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

記住跨頁面選中的復選框 - 最好的方法是什么?

Remembering checked checkboxes across pages - what#39;s the best way?(記住跨頁面選中的復選框 - 最好的方法是什么?)
本文介紹了記住跨頁面選中的復選框 - 最好的方法是什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我需要添加類似于 Gmail 的功能,其中項目列表上的復選框會在多個結果頁面以及離開和返回結果時記住.我想弄清楚的是最好的方法.我正在使用 PHP,可能還有 jQuery.

I'm needing to add functionality similar to Gmail where the checkboxes on a list of items is remembered across multiple pages of results and when going away and coming back to the result. What I'm trying to figure out is the best way of doing this. I'm using PHP and likely jQuery.

我的第一個想法是向每個復選框添加一個 onClick,以觸發 AJAX 調用返回服務器,該服務器將 id 存儲在會話中的數組中.每次加載項目列表時,系統都會檢查該行是否被選中,并在必要時選中復選框.為了可靠性,在檢查到服務器的請求是否無法完成(連接問題、服務器錯誤等)后,將取消選中該復選框,并盡可能快地發出請求.

My first thought is to add an onClick to each checkbox that triggers an AJAX call back to the server which stores the id in an array in the session. Each time a list of items is loaded, the system would check to see if the row is checked and check the checkbox if necessary. For reliability, the checkbox would be unchecked after checking if the request to the server cannot be completed (connection problem, server error, etc) and the request would be made as quick as absolutely possible.

這聽起來都不錯,除了一些項目:

This sounds all good, except for a few items:

  • 檢查所有:會發生什么?它是否向服務器發送 30 個(默認頁面項目)請求?或者我是否刪除所有 onClicks,選中復選框,向服務器發送包含所有 id 的請求,然后重新添加 onClicks?或者...?取消選中所有類似的問題.
  • 速度:如果 100 多位用戶一直在檢查和取消檢查,可能會開始出現問題
  • 瀏覽器速度:我認為最好在頁面加載后使用 JS 添加 onClick,如果一個頁面上有 500 個或更多項目,我認為這可能需要一兩秒鐘.全部檢查會成為一個更大的問題.

過去我沒有找到一種可靠的方法來檢測用戶何時離開頁面.如果有可靠的方法,那么我可以將其視為一個選項,因此它只會在每個頁面卸載時進行記錄.

In the past I haven't found a reliable way to detect when the user leaves a page. If there is a reliable way, then I could see this being an option so it just records on each page unload.

是否有其他解決方案或更好的方法?

Are there any other solutions or better methods?

如Eran Galperin,check all 方法只需要檢查每個復選框,然后對所有行進行 ajax 調用.無需刪除 onClick.

As mentioned by Eran Galperin, the check all method would only need to check each of the checkboxes and then make an ajax call with all of the rows. No need to remove the onClick.

另外,看起來事件委托方法是個好主意——會讓事情變得更容易.

Also, it looks like the Event Delegation method is a good idea—would make things a lot easier.

推薦答案

  1. 當您以編程方式更改復選框的選中狀態時,不會觸發 onclick 事件.當用戶點擊全選/取消全選鏈接時,您可以發送不同的 AJAX 請求,而不必擔心附加到各個復選框的點擊事件.
  2. 這是使用每次點擊請求時的權衡.或者,使用保存"按鈕來保存整個表單.
  3. 使用事件委托 - 附加一次點擊事件到包含所有復選框的整個容器,并檢查事件的目標以查看是否單擊了復選框.另外,我個人會避免在同一頁面上顯示 500 個不同的選項.如果絕對需要有這么多選項,請將它們分解為多個區域/頁面.
  1. An onclick event won't trigger when you programmaticaly change the checked status of a checkbox. You can send a different AJAX request when a user clicks the check all / uncheckall link, without worrying about the click events you attached to individual checkboxes.
  2. This is the tradeoff when using a request per click. Alternatively use a "Save" button that saves the entire form.
  3. Use event delegation - attach one onclick event to the entire container that holds all the checkboxes, and check the target of the event to see if a checkbox was clicked. Also, personally I would avoid showing 500 different options on the same page. If absolutely necessary to have so many options, break them down into several zones / pages.

對于離開頁面的用戶,您可以使用 onbeforeonload事件,但是如果瀏覽器崩潰或以其他方式不正常退出,它將不會被捕獲.根據捕獲用戶更改的關鍵程度來使用它.

For a user leaving the page you can use the onbeforeonload event, however if the browser crashes or otherwise exits ungracefully it will not be caught. Use it depending on how critical is it to be able to capture user changes.

這篇關于記住跨頁面選中的復選框 - 最好的方法是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 欧美日韩国产不卡 | 国产精品久久久久久久三级 | 欧美xxxx性xxxxx高清 | 国产高潮好爽受不了了夜色 | 亚洲日日操 | 午夜精品一区二区三区在线视频 | 日本久久久久久 | 亚洲中午字幕 | 91成人在线视频 | 亚洲一区二区三区在线 | 日韩成人精品一区二区三区 | 成人av电影免费在线观看 | 日韩成人在线观看 | 精品久久99 | 欧美日韩综合 | 欧美亚洲国语精品一区二区 | 欧美一区二区三区在线看 | 在线视频 中文字幕 | 黄色网址在线免费观看 | 国产99久久久国产精品 | 国产精品久久国产精品 | 国产日产久久高清欧美一区 | 国产高清自拍视频在线观看 | 国产三级日本三级 | 91精品国产91久久久久游泳池 | 国产福利在线免费观看 | 一级免费毛片 | 成人久久18免费网站图片 | 红桃视频一区二区三区免费 | 日韩av一区二区在线观看 | 国产精品一二区 | 亚洲精品一区二区 | 午夜成人免费视频 | 国产精品久久久久久婷婷天堂 | 中文字幕在线不卡 | 久久午夜精品 | 女女爱爱视频 | 成人综合一区二区 | 午夜伊人 | 韩国精品在线 | 婷婷国产一区二区三区 |