Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
jQuery URL拆分和抓取_Jquery_Url_Split - Fatal编程技术网

jQuery URL拆分和抓取

jQuery URL拆分和抓取,jquery,url,split,Jquery,Url,Split,所以我有一个URL,我知道如何从URL获取$\u get,但是我的URL是http://www.example.com/#!/编辑/2695 有没有办法抓取url并吐出#之后的部分/?我需要编辑和ID。您可以使用此代码 var url = "http://www.mysite.com/#!/edit/2695"; var pieces = url.split("/#!/"); pieces = pieces[1].split("/"); // pieces[0] == "edit" // pi

所以我有一个URL,我知道如何从URL获取$\u get,但是我的URL是
http://www.example.com/#!/编辑/2695

有没有办法抓取url并吐出
#之后的部分/?我需要编辑和ID。

您可以使用此代码

var url = "http://www.mysite.com/#!/edit/2695";
var pieces = url.split("/#!/");
pieces = pieces[1].split("/");

// pieces[0] == "edit"
// pieces[1] == "2695"
如果您只是想在编辑后输入数字,还可以使用正则表达式

var url = "http://www.mysite.com/#!/edit/2695";
var match = url.match(/#!\/edit\/(\d+)/);
if (match) {
    // match[1] == "2695"
}

您可以在这里看到这两个解决方案:

您需要
php
还是JavaScript`解决方案?谢谢!拆分url对我帮助很大
var edit = window.location.hash.split('/')[1],
      ID = window.location.hash.split('/')[2];