我試圖替換字符串是這樣的:JavaScript字符串替換錯誤:變量未定義
var thecurrentURL = 'IAmATextString=12345'
thecurrentURL = thecurrentURL.replace('IAmATextString', '').split('=');
thecurrentURLvalue = thecurrentURL[1];
如果我提醒這個喜歡
alert(thecurrentURLvalue);
它返回正確的字符串。現在我想檢查字符串是正確的,它在一個div
if (thecurrentURLvalue == '12345') {
$('#Title').html('12345');
}
寫當我嘗試檢查它不工作,並返回
TypeError: thecurrentURL is undefined
thecurrentURL = thecurrentURL.replace('IAmATextString', '').split('=');
問題是什麼?謝謝!
是你缺少 ';'在var thecurrentURL ='IAmATextString = 12345'結尾處; – HICURIN
@hicurin不會有所作爲,這裏一定有其他的錯誤Marc,我沒有看到任何問題 – iConnor
這似乎工作得很好http://jsfiddle.net/mMLU5/ - 你確定你不'你的代碼中有一些額外的範圍? –