<a href="<?php echo base_url(); ?>userprofile/userprofile/2" style="color:white; margin-top:2rem;" onclick="senduser(2);">User2</a>點擊“User2”后,頁面刷新。但是為了獲得圖像,我需要向我的 app.js 文件發送一個 Id 值。我嘗試使用 onclik 功能提供此功能。很遺憾!頁面刷新后不能!function senduser($id){ var limit_load = 5; var start_load = 0; var userId = $id; function load_photo_profile(limit_load, start_load, userId) { var url = baseUrl + "userprofile/loadmore"; $.post(url, { limit: limit_load, start: start_load, userId: userId }, function (response) { $(".included_image").append(response); $('#mygallery').justifiedGallery({ rowHeight: 285, lastRow: 'nojustify', margins: 10 }); }); }; load_photo_profile(limit_load, start_load, userId); $(window).scroll(function () { if ($(window).scrollTop() >= $(document).height() - $(window).height()) { start_load = start_load + limit_load; load_photo_profile(limit_load, start_load, userId); } });}這個 id 觸發完全地工作這個功能。跟隨它觸發 ajax post 方法以在 mygallery 元素內呈現代碼。另一方面,我必須刷新我的頁面。
2 回答

瀟湘沐
TA貢獻1816條經驗 獲得超6個贊
您可以使用sessionStorage來保存您需要的值,因此在刷新頁面后,您可以訪問該值,您可以像這樣創建它:
sessionStorage.setItem('nameOfItem', "mysavedValue");
為了訪問這個sessionStorage
值:
sessionStorage.getItem('nameOfItem')

猛跑小豬
TA貢獻1858條經驗 獲得超8個贊
會話存儲是臨時的,只要當前窗口打開,數據就會在窗口關閉時丟失,而本地存儲是持久的,并且在會話之間保持完整,除非有人刪除它。
localStorage.setItem("nameOfItem","valueofitem");//set
localStorage.getItem("nameOfItem"); //get
- 2 回答
- 0 關注
- 172 瀏覽
添加回答
舉報
0/150
提交
取消