How do I get the fragment identifier (value after hash #) from a URL?
问题 Example: www.site.com/index.php#hello Using jQuery, I want to put the value hello in a variable: var type = … 回答1: No need for jQuery var type = window.location.hash.substr(1); 回答2: You may do it by using following code: var url = "www.site.com/index.php#hello"; var hash = url.substring(url.indexOf('#')+1); alert(hash); SEE DEMO 回答3: var url ='www.site.com/index.php#hello'; var type = url.split('#'); var hash = ''; if(type.length > 1) hash = type[1]; alert(hash); Working demo on jsfiddle 回答4: