目前我使用Ben's Alman的jquery-hashchange插件在哈希中使用页面编号:
$(document).ready(function(){
$(window).hashchange( function(){
var hash = (location.hash) ? location.hash.slice(1) : 'page1';
$.ajax({
url: '/list/' + hash, // result url like page1, page2 etc.
现在我需要添加一个值 -
filter
。
我认为结果哈希URL可能会像这样:#page1&filter=1-1-0
#filter=1-1-0 (if page number is omitted)
#page1 (if filter is not defined)
如何解析这个问题?也就是说,如何了解是否定义了
page
,是否定义了filter
(以及值是什么- 1
、1
和 0
- 我需要它们分开)?我考虑过Ben's Alman的BBQ插件,但是(1)它对于如此简单的任务来说看起来太复杂了,(2)不确定如何在没有值的情况下使用参数(page1, page2等)。
document.location.hash = "somehash";
。所以,你可以这样做:if(document.location.hash.length > 0) { ... 做一些事情... }
。 - Oroboros102