代码之家  ›  专栏  ›  技术社区  ›  Muhammad Awais

Jquery散列集函数

  •  1
  • Muhammad Awais  · 技术社区  · 8 年前

    window.location.hash = "#globalSearchView";
    

    当前我正在使用哈希更改函数

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

    它只在哈希被更改时工作,但在相同哈希时不工作。我想调用函数 每当这条线

    window.location.hash = "#whatever";
    

    无论是同一哈希还是不同哈希都执行。谢谢

    1 回复  |  直到 8 年前
        1
  •  0
  •   Brian Patterson    8 年前

    也许是这个?

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