Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.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
Javascript 从url中提取_Javascript_Jquery_Asp.net_Url_Hyperlink - Fatal编程技术网

Javascript 从url中提取

Javascript 从url中提取,javascript,jquery,asp.net,url,hyperlink,Javascript,Jquery,Asp.net,Url,Hyperlink,我只想从下面的链接中提取Services.aspx http://localhost:49169/HirenSir/Services.aspx 使用jQuery/javascript是令人钦佩的,因为随后必须向包含此href参数的锚定标记添加一个类 谢谢用Javascript试试这个 var curPage = location.pathname.substring(location.pathname.lastIndexOf("/") + 1); 如果您当前的位置是Services.aspx

我只想从下面的链接中提取Services.aspx

http://localhost:49169/HirenSir/Services.aspx

使用jQuery/javascript是令人钦佩的,因为随后必须向包含此href参数的锚定标记添加一个类

谢谢用Javascript试试这个

var curPage = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
如果您当前的位置是Services.aspx

编辑

如果您想在这种情况下向锚点添加类,请尝试以下操作

$('a[href$="Services.aspx"]').addClass('selected');

到目前为止,所有的解决方案都有效。。。正则表达式怎么样

var url = "http://localhost:49169/HirenSir/Services.aspx";

// returns array of matches, should only contain one element 
url.match("[^/]*$"); // ["Services.aspx"]
如果你想要一行的话

"http://localhost:49169/HirenSir/Services.aspx".match("[^/]*$")[0];

你需要更具体一些。。。从什么中提取?Perl脚本中的字符串?文本文件中的一行?两个大问题:这些URL是如何存储的,您希望用什么语言提取?另外,您尝试做的事情是否有某种模式?您的要求是什么?如果给定的解决方案对您有所帮助,您应该接受答案。我刚刚开始为该::P开发JDFIDLE
"http://localhost:49169/HirenSir/Services.aspx".match("[^/]*$")[0];