我試圖從url中讀取查詢字符串,並根據查詢字符串提醒消息。字符串正在完美傳遞,我只是在閱讀頁面時遇到麻煩。我究竟做錯了什麼?jquery從url中獲取查詢字符串
可能的查詢字符串
.../playlist.html?vid=1
.../playlist.html?vid=2
JS
$(function() {
if (window.locaion.search.indexOf('vid=1') > -1) {
alert('1');
} else if (window.locaion.search.indexOf('vid=2') > -1) {
alert('2');
}
});
locaion是一個錯字嗎? – 2012-02-10 22:46:15
你已經寫了'locaion'而不是'location'。在你的運行代碼中是否有錯字,或者只是在這裏的問題? – Rophuine 2012-02-10 22:46:49
錯字?嘗試位置,而不是你有什麼。 – 2012-02-10 22:46:54