2012-02-12 92 views
2

我想摆脱URL信息使用jQuery:获取URL的一部分使用jQuery

login 

从这个网址:

http://www.domain.com/index.html#login 

所以我想什么,是让来自# 的信息以及稍后使用我从#获得的信息制作包含。 我知道如何包含一个文件,但我不知道如何从网址获取信息,并从“#”

我不是真的想用& site = login,因为这是我的最后一个选项。

回答

4

为什么不使用window.location.hash

0

window.location对象有一个hash属性。

console.log(window.location.hash); 

分手的值,如果有多个具有:

window.location.hash.split('#'); 
0

使用jQuery

var loc = $(window)[0].location; 
var thingYouWant = $(loc).prop('hash').substr(1); 
+0

谢谢,它的工作原理。 – Kristjan 2012-02-12 14:43:24

+2

@Kristjan:哇,我正在讽刺,用[karim79's](http://stackoverflow.com/a/9249432/465546)回答。我的方式是[Rube Goldberg](http://en.wikipedia.org/wiki/Rube_Goldberg_machine)方式。你不需要这个jQuery。 – qwertymk 2012-02-12 18:19:41