如何使用jquery獲取以下URL的id表單?如何從網址獲取ID?
http://localhost:8080/moduloESR/actualiza_evento.php?id=1009
我只是想借此:1009
如何使用jquery獲取以下URL的id表單?如何從網址獲取ID?
http://localhost:8080/moduloESR/actualiza_evento.php?id=1009
我只是想借此:1009
你不需要jQuery的這一點。只要創建一個這樣的功能:
function getParam(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
然後調用,傳遞你想要的值:
var id = getParam('id');
一個班輪溶液張貼在這裏: How to get URL parameters with Javascript? 我引述:
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null
}
所以你可以使用:
myvar = getURLParameter('myvar');
或者你的情況:不需要
id = getURLParameter('id');
jQuery的。
儘管這個鏈接可能回答這個問題,但最好在這裏包含答案的基本部分,並提供參考鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 –
更新了答案,以包含我之前鏈接中最重要的部分。 – abali96
這是回答您的問題嗎? http://stackoverflow.com/questions/19491336/get-url-parameter-jquery –