這是我與HREF如何在html鏈接中發送參數以及如何檢索它?
<a href='components/home/singleActivity.html?view="search"'>
....
</a>
我想送一個字符串參數html標記,它是正確的方法是什麼?
如何在JavaScript中檢索該參數?以及如何爲相同的href發送2個參數?
這是我與HREF如何在html鏈接中發送參數以及如何檢索它?
<a href='components/home/singleActivity.html?view="search"'>
....
</a>
我想送一個字符串參數html標記,它是正確的方法是什麼?
如何在JavaScript中檢索該參數?以及如何爲相同的href發送2個參數?
嘗試
<a href='components/home/singleActivity.html?view=Search&test2=New'>
MyLink
</a>
爲了發送該參數的URL,你DONOT需要附上內部報價的價值('')
或雙引號("")
。你只需要發送的值(或多個值),如下圖所示..
components/home/singleActivity.html?view=search&secondvalue=anythingthatyouthinkof
也請記住,你需要跟蹤的URL編碼的。
而用於檢索參數this thread詳細解釋它。
它應該是不帶引號components/home/singleActivity.html?view=search
發送兩個參數加入他們與&
components/home/singleActivity.html?foo=bar&baz=quux
讀他們在JavaScript中使用此代碼:
var params = {};
location.search.slice(1).split("&").forEach(function(pair) {
pair = pair.split("=");
params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
});
要發送,您可以使用?view=search&key2=value2&key3=value3
多個值和等等。
此外,要訪問這些參數,您可以使用window.location訪問URL。
喜歡的東西
var params = window.location.split('?')[1];
這之後給你的一切嗎?在URL中。
拆分是字符串的方法不是函數。 – jcubic
我的不好。編輯;-)謝謝 –