How do I get the fragment identifier (value after

2019-01-03 02:15发布

Example:

www.site.com/index.php#hello

Using jQuery, I want to put the value hello in a variable:

var type = …

7条回答
够拽才男人
2楼-- · 2019-01-03 02:53

Based on A.K's code, here is a Helper Function. JS Fiddle Here (http://jsfiddle.net/M5vsL/1/) ...

// Helper Method Defined Here.
(function (helper, $) {
    // This is now a utility function to "Get the Document Hash"
    helper.getDocumentHash = function (urlString) {
        var hashValue = "";

        if (urlString.indexOf('#') != -1) {
            hashValue = urlString.substring(parseInt(urlString.indexOf('#')) + 1);
        }
        return hashValue;
    };
})(this.helper = this.helper || {}, jQuery);
查看更多
登录 后发表回答