PHP有$ _GET变量,HTML有什么? [英] PHP has $_GET variable, what does HTML have?

查看:167
本文介绍了PHP有$ _GET变量,HTML有什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如果我有一个php页面,我可以通过带有$ _GET的url将变量传递到下一页。如:

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"]

是否有一种简单的方法可以在纯HTML中执行此操作(或javascript)?

推荐答案

使用 jQuery 可以通过 window.location 获取url参数,但是使用 regex

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');

或与JS

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

urlParameter('Parameter  name');

这篇关于PHP有$ _GET变量,HTML有什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆