Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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 uptp所需的查询字符串jQuery_Javascript_Jquery_Url_Query String - Fatal编程技术网

Javascript 获取url uptp所需的查询字符串jQuery

Javascript 获取url uptp所需的查询字符串jQuery,javascript,jquery,url,query-string,Javascript,Jquery,Url,Query String,考虑一下我的url就像 http://localhost:4588/home?name=test&value=2003&view=current&index=1&.... 我需要将url转到“查看”查询字符串 这在jQuery中可能吗 编辑: url中的前三个值单独为常量(名称、值和视图),在“视图”之后将发生更改。因此,我只需要获取最多“查看”查询字符串。您可以使用split()拆分url: var url=”http://localhost:4588/home?name=test&valu

考虑一下我的url就像
http://localhost:4588/home?name=test&value=2003&view=current&index=1&....

我需要将url转到“查看”查询字符串

这在jQuery中可能吗

编辑:


url中的前三个值单独为常量(名称、值和视图),在“视图”之后将发生更改。因此,我只需要获取最多“查看”查询字符串。

您可以使用
split()拆分url

var url=”http://localhost:4588/home?name=test&value=2003&view=current&index=1&....";

console.log(url.split('&index')[0])
您可以使用
split()
拆分url:

var url=”http://localhost:4588/home?name=test&value=2003&view=current&index=1&....";

console.log(url.split('&index')[0])
您可以通过以下方式获得它:

var-str='http://localhost:4588/home?name=test&value=2003&view=current&index=1&'
var模式=新的RegExp(/view=[a-zA-Z0-9]*/)//这是查找view=somevalue的正则表达式(其中somevalue将仅包含字母和数字)
var i=pattern.exec(str);//这将提取view=current字符串
log('matched view=current-->',i);
log('search for index of view=current in our string',str.indexOf(i[0]);
console.log('length of view=current string-->'+i[0].length);
var final=str.substr(0,str.indexOf(i[0])+i[0].length);//添加索引+视图长度=current,并将其作为第二个参数传递给substring函数

console.log(最终版);
您可以通过以下方式获得它:

var-str='http://localhost:4588/home?name=test&value=2003&view=current&index=1&'
var pattern=new RegExp(/view=[a-zA-Z0-9]*/);//这是查找view=somevalue的正则表达式(其中somevalue将只包含字母和数字
var i=pattern.exec(str);//这将提取view=current字符串
log('matched view=current-->',i);
log('search for index of view=current in our string',str.indexOf(i[0]);
console.log('length of view=current string-->'+i[0].length);
var final=str.substr(0,str.indexOf(i[0])+i[0].length);//添加索引+视图长度=current,并将其作为第二个参数传递给substring函数

console.log(最终版)
是的,这是可能的,请告诉我们您尝试了什么所需的输出是:
http://localhost:4588/home? name=test&value=2003&view=current
?@HamzaAbdaoui是的。如果可能的话,请告诉我们您尝试了什么。所需的输出是:
http://localhost:4588/home? name=test&value=2003&view=current
?@HamzaAbdaoui是前三个单独的值常量(名称、值和视图)…在“查看”之后它将更改..因此我无法获取索引[0]。前三个单独的值常量(名称、值和视图)…在“查看”之后它将更改..因此我无法获取索引[0]。