2013-04-14 36 views
-5

大家好我有一個網址會看起來像這樣如何從URl獲取特定的字符串?

 http://localhost:60255/Roles/12/Users/ 

我需要使用jquery從窗口從HREF得到這個,我應該從上單擊事件的URL獲得這個字符串

 http://localhost:60255/Roles/ 

this is what i had been trying 

     var windowpathname = window.location.pathname; window.location.href = windowpathname + "Roles/" + RoleID + "/" + RoleName; 
在這種情況下

當我點擊第二次

 http://localhost:60255/Roles/12/Rahul/Roles/14/Kishore/ 
+1

你爲什麼不只是使用'HTTP://本地主機:60255 /角色/' –

+0

我將改變每次點擊的ID值 – user1831498

+0

@MohammadAdil我編輯了我的問題你可以檢查一次 – user1831498

回答

0

對象了window.location的一些特性:

hash: "" 
host: "fiddle.jshell.net" 
hostname: "fiddle.jshell.net" 
href: "http://fiddle.jshell.net/_display/" 
origin: "http://fiddle.jshell.net" 
pathname: "/_display/" 
+0

我編輯過我的問題..你可以看看它一次 – user1831498

0

你可以試試這個

window.location.href = window.location.hostname + "/Roles/" + RoleID + "/" + RoleName; 
相關問題