【问题标题】:Jquery hash set functionjQuery哈希集函数
【发布时间】:2018-12-14 15:44:38
【问题描述】:

每当执行此行时,我都需要调用一个函数

window.location.hash = "#globalSearchView";

目前我正在使用哈希更改功能

$(window).on("hashchange",function(e) {
    var hash = window.location.hash;
    switchtabs(hash);
});

它仅在哈希更改时有效,但在哈希相同时无效。我想在这一行时调用一个函数 switchtabs

window.location.hash = "#whatever";

无论哈希相同或不同,都会执行。谢谢

【问题讨论】:

    标签: jquery hash tabs hashchange


    【解决方案1】:

    也许是这个?

    var l = location.prototype;
    Object.defineProperty(l, 'hash', {
      get: function() { return this.hash; },
      set: function(t) { this.hash = t; switchtabs(t); }
    });
    

    【讨论】:

    • 不,它不起作用...它只是在浏览器哈希中添加函数的整个语法
    猜你喜欢
    • 1970-01-01
    • 2017-09-30
    • 2016-03-25
    • 2011-02-27
    • 2011-08-04
    • 2011-07-10
    • 2022-01-03
    • 2011-02-04
    • 2019-07-24
    相关资源
    最近更新 更多