html拼hash会缓存么,window.location.href与.html之后的#hash

您可以使用以下代码实现哈希检查:

$( document ).ready(

function () {

// Get the current URL

var loc = window.location.href;

// Get the hash part

var hash = window.location.hash.replace( '#', '' );

if (

// If the location contains the word user

/user/.test( loc ) &&

// and the hash string has length greater than 0

0 < hash.length &&

// and the hash contains the string /details

/\/details/.test( hash )

) {

// Do stuff related to user page

// with the details hash part

}

}

);

此外,如果您想使其更复杂,您可以使用以下代码:

(function( $, window, undefined ) {

// Handle the page elements related to the hash parts

var track_hash_changes = function track_hash_changes() {

// Get the current URL

var loc = window.location.href;

// Get the hash part

var hash = window.location.hash.replace( '#', '' );

if (

// If the location contains the word user

/user/.test( loc )

) {

switch( hash ) {

case '/case-1':

// Do stuff for case #1

break;

case '/case-2':

// Do stuff for case #2

break;

case '/case-X':

// Do stuff for case #X

break;

}

}

};

$( document ).ready(

function () {

// Listen for changes in the Hash part of the URL

window.addEventListener("hashchange", track_hash_changes, false);

}

);

})( jQuery, this );

其中case-1,case-2,case-X是user.html#/case-1,user.html#/case-2,user.html#/case-X

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值