2017-03-05 25 views
1

簡單,我這樣做:str.indexOf不是函數錯誤嗎?

var loc = window.location; 
var fltURI=loc.substr(loc.indexOf("hey?hi=")+7, loc.length); 
alert(fltURI); 

而我得到的錯誤。 請解釋一下爲什麼?

問候

回答

2

window.location的是一個位置的對象,而不是字符串

嘗試:

var loc = window.location.toString(); 
var fltURI=loc.substr(loc.indexOf("hey?hi=")+7, loc.length); 
alert(fltURI); 
0

使用LOC作爲一個字符串...

var loc = window.location.toString(); 
 
alert(loc); 
 
var fltURI=loc.substr(loc.indexOf("hey?hi=")+7, loc.length); 
 
alert(fltURI);