var url = window.location.href;
https://test.com/index.html?Event=90000002
我如何使用JavaScript來獲取90000002
並把它放在一個變量?
var url = window.location.href;
https://test.com/index.html?Event=90000002
我如何使用JavaScript來獲取90000002
並把它放在一個變量?
雖然這不是最佳的方式,但你仍然可以做這樣的
使用location
對象,它是搜索屬性。
location.search將返回?Event=90000002
。然後使用substring
來獲取值
var a = location.search;
console.log(a.substring(7,a.length))
謝謝,這也看起來像一個非常簡單的解決方案,適用於我。 – Preamas
整個文本,包括之後的'?'是'window.location.search' –
有堆棧各種查詢字符串函數..只是搜索並挑選一個。 – Lain
可能的重複[如何在JavaScript中獲取查詢字符串值?](http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) –