如何從URL地址檢索變量? 正在使用此代碼,但它不工作:#js中的URL地址中的變量
var x=window.location;
var y = x.indexOf('#', 0);
x=x.substring(y,x.length);
我收到以下錯誤:
Error: x.indexOf is not a function
如何從URL地址檢索變量? 正在使用此代碼,但它不工作:#js中的URL地址中的變量
var x=window.location;
var y = x.indexOf('#', 0);
x=x.substring(y,x.length);
我收到以下錯誤:
Error: x.indexOf is not a function
你想要的是不是window.location的,但window.location.href
不過,我會用window.location.hash約`location`
你得到的錯誤,因爲window.location
是一個對象,而不是字符串。嘗試window.location.hash
以獲得#
之後的部分。
我認爲window.location.hash包含#字符。 – Marcelo 2011-03-17 13:39:46
更多信息:HTTPS://developer.mozilla。 org/en/DOM/window.location – 2011-03-17 08:26:34