浏览器后退按钮,用css隐藏div

时间:2018-03-26 07:29:37

标签: javascript jquery browser-history

我有一个网站,其中显示房地产属性搜索结果,如使用var request = global.get('requestModule'); var fs = global.get('fsModule'); msg.body = {}; msg.body = { 'apikey' : "**********", 'wav' : fs.createReadStream('/tmp/testtest.wav') }; msg.headers = {}; msg.headers['Content-type'] = 'multipart/form-data'; return msg s,默认只显示6,并“加载更多”按钮。当用户单击“加载更多”按钮时,会显示另外9个帖子,等等。如何完成:<div>默认隐藏(div),然后将display: none;类添加到下一个9项目

.show

当用户转到单个属性然后点击浏览器按钮时,它会再次显示前6个项目。我尝试在那里实现a("span.more-search-items").on("click", function(t) { t.preventDefault(); var e = a(this).parents(".property-search"); e.find(".prop").not(".show").slice(0, 9).each(function() { var t = a(this).attr("data-img"); a(this).css("background-image", "url(" + t + ")"), a(this).find(".main-image").attr("src", t), a(this).addClass("show") }), 0 == e.find(".prop").not(".show").length && a("span.more-search-items").hide(); e.find(".prop.show").length 方法,其中每个“加载更多”按钮的URL更改单击:

history.pushState()

网址更改但故事仍然相同 - 当用户返回历史记录时,仅显示前6个结果。在这种情况下我能做些什么吗?

1 个答案:

答案 0 :(得分:1)

如果您需要处理#15 , #24,则需要

  • 加载更多点击后,您需要推送或替换历史记录,例如带有哈希值$(window).on('popstate' , function(){ alert(window.location.hash); })的可见div数量

  • 使用推送/替换状态,您需要使用alert(window.location.hash);,当用户转到单个属性时,它会刷新所有页面,当点击浏览器后退按钮时,它会返回并刷新上一页..所以你需要在页面加载时检查window.location.hash

最后,当您收到来自$(document).ready(function(){ alert(window.location.hash); // check the alert here $('.load_more_button').on('click' , function(){ if(window.location.hash){ var href = window.location.href.split('#'); var currentPage = parseInt(window.location.hash); history.pushState(null, null, href[0] + "#" + (+currentPage + 1)); } }); $(window).on('popstate' , function(){ alert(window.location.hash); // check the alert here }); }); 的号码的提醒时,您可以根据它显示div

好的,让我在代码

中为您解释一下
exit

你可以从这里开始,当你得到你喜欢的号码时

相关问题