Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
URL Javascript-Form:/index.html#/?id=1426591453147中的参数_Javascript_Jquery_Url_Web_Parameters - Fatal编程技术网

URL Javascript-Form:/index.html#/?id=1426591453147中的参数

URL Javascript-Form:/index.html#/?id=1426591453147中的参数,javascript,jquery,url,web,parameters,Javascript,Jquery,Url,Web,Parameters,我正在尝试使用JavaScript或jQuery从当前url获取参数。 URL如下所示: http://my-site.com/index.html#/?id=1426591453147 或 我尝试了一些“location.search”代码,但location.search在我的URL上返回一个空字符串 有人知道解决这个问题的好办法吗 编辑: 我最后用了这个: function getParameterByName(name) { name = name.replace(/[\[]/

我正在尝试使用JavaScript或jQuery从当前url获取参数。 URL如下所示:

http://my-site.com/index.html#/?id=1426591453147

我尝试了一些“location.search”代码,但location.search在我的URL上返回一个空字符串

有人知道解决这个问题的好办法吗

编辑: 我最后用了这个:

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?]" + name + "=([^&#]*)"),
        results = regex.exec(location.hash);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
像这样的?(适用于您的具体案例

所以


location.search
在URL的格式为:
example.com?foo=bar
时起作用。但是您的“查询字符串”前面是
,因此,字符串的其余部分是通过
location.hash来访问的http://my-site.com/index.html#/?id=1426591453147“.replace(/^.*?\.com(.*?$/i,'$1')
我最终使用了zvonas的答案。谢谢
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?]" + name + "=([^&#]*)"),
        results = regex.exec(location.hash);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
"http://my-site.com/index.html#/?id=1426591453147".replace(/^.*?\.com(.*?)$/i, '$1'); // "/index.html#/?id=1426591453147"

"http://my-site.com/#/?id=1426591453147".replace(/^.*?\.com(.*?)$/i, '$1'); // "/#/?id=1426591453147"
location.href.replace(/^.*?\.com(.*?)$/i, '$1');