PHP has $_GET variable, what does HTML have? [duplicate]

本秂侑毒 提交于 2019-12-11 18:59:43

问题


I know if I have a php page, I can pass variables to the next page through the url with $_GET. Such as:

http://www.w3schools.com/welcome.php?fname=Peter&age=37

yields:

$currentName = $_GET["fname"]
$currentAge = $_GET["age"]

Is there an equally easy way to do this in pure HTML (or javascript)?


回答1:


using jQuery you can get url parameters with window.location but parsing with regex

$.urlParameter = function(name){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    return results[1] || 0;
}

$.urlParameter('Parameter  name');

OR with JS

function urlParameter(name){
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    return results[1] || 0;
}

urlParameter('Parameter  name');


来源:https://stackoverflow.com/questions/17372026/php-has-get-variable-what-does-html-have

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!