Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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 如何使用jquery解析URL_Javascript_Jquery_Html - Fatal编程技术网

Javascript 如何使用jquery解析URL

Javascript 如何使用jquery解析URL,javascript,jquery,html,Javascript,Jquery,Html,我有以下网址: /html5/test2, /html5/test1 我需要得到html5之后的值,在本例中是test2,test1。如何使用jquery实现这一点?您使用JavaScript中的substring和lastIndexOf或split方法 1. var url = "/html5/test2"; console.log(url.substring(url.lastIndexOf("/")+1,url.length)); //test2 var urlStr = "/html5

我有以下网址:

/html5/test2,
/html5/test1

我需要得到html5之后的值,在本例中是test2,test1。如何使用jquery实现这一点?

您使用JavaScript中的
substring
lastIndexOf
split
方法

1.

var url = "/html5/test2";
console.log(url.substring(url.lastIndexOf("/")+1,url.length)); //test2
var urlStr = "/html5/test2".split("/");
urlStr[urlStr.length-1]; //test2
2.

var url = "/html5/test2";
console.log(url.substring(url.lastIndexOf("/")+1,url.length)); //test2
var urlStr = "/html5/test2".split("/");
urlStr[urlStr.length-1]; //test2

您还可以按如下方式使用
split
功能:

var str = "/html5/test1";
var test = str.split("/")[2];
console.log(test); //gives test1

您不需要jQuery。获取路径名
窗口.location.pathname
并使用
split()


它的简单如下使用和

以下是您要做的:

var pathPart = location.pathname.split("/").pop();

您可以使用此代码获取url的最后一个字符串

<%      

        String modifiedPath1 = request.getAttribute("javax.servlet.forward.request_uri").toString(); //services/order_taking
        int lastIndex = modifiedPath1.lastIndexOf("/");
        modifiedPath1 = modifiedPath1.substring(lastIndex,modifiedPath1.length());
        modifiedPath1=modifiedPath1.replaceAll("/","");
        System.out.println("the modified path" +modifiedPath1);

    %>


你是说你想阅读你当前所在页面的URL,还是说你有两个字符串恰好是URL?我太匆忙了,谢谢你的通知!我删除了标记的评论@JavaScriptYou需要展示更多的例子,否则这不是jquery的问题,在由javascript、jquery和html组成的三个类别中,这一个属于哪一个?您把它放在jsp页面中。