基于javascript、jquery的qts

基于javascript、jquery的qts,javascript,jquery,Javascript,Jquery,如何使用js或jquery从提取的url中提取字符串?带有substring函数,该函数获取所提供索引之间的字符 例如,如果您在http://stackoverflow.com/questions alert(location.href.substring(7, 20)) 将显示“stackoverflow” 我看到您以前问过类似的问题,如果您解释为什么需要这样做,我们可以使用substring函数更好地帮助您,该函数获取提供的索引之间的字符 例如,如果您在http://stackoverfl

如何使用js或jquery从提取的url中提取字符串?

带有substring函数,该函数获取所提供索引之间的字符 例如,如果您在
http://stackoverflow.com/questions

alert(location.href.substring(7, 20))
将显示“
stackoverflow


我看到您以前问过类似的问题,如果您解释为什么需要这样做,我们可以使用substring函数更好地帮助您,该函数获取提供的索引之间的字符 例如,如果您在
http://stackoverflow.com/questions

alert(location.href.substring(7, 20))
将显示“
stackoverflow


我看到您以前问过类似的问题,如果您解释为什么需要这样做,我们可以更好地帮助您

您可以使用正则表达式解析URL-请参阅

根据您的评论,另一个例子是:

var url = 'http://localhost:8080/Sample/ex1/sample1.jsp?cuId=U113&pid=123&anotherKey=anotherValue'
var re = /.+?cuId=(.*)&pid=([^&]*)/;
var tokens = url.match(re);
var cuId = tokens[1];
var pid = tokens[2];
alert('cuId: ' + cuId);
alert('pid: ' + pid);

您可以使用正则表达式解析URL-请参阅

根据您的评论,另一个例子是:

var url = 'http://localhost:8080/Sample/ex1/sample1.jsp?cuId=U113&pid=123&anotherKey=anotherValue'
var re = /.+?cuId=(.*)&pid=([^&]*)/;
var tokens = url.match(re);
var cuId = tokens[1];
var pid = tokens[2];
alert('cuId: ' + cuId);
alert('pid: ' + pid);

String.substr-您是否试图提取某个节或某个子串/模式?String.substr-您是否试图提取某个节或某个子串/模式?假设url为http:localhost:8080/Sample/ex1/sample1.jsp?cuId=U113&pid=123,现在我必须为cuId和pid设置标题@贾格蒂:我想,我的答案是可行的解决方案。也许应该接受。假设url是http:localhost:8080/Sample/ex1/sample1.jsp?cuId=U113&pid=123,现在我必须对cuId和pid进行验证@贾格蒂:我想,我的答案是可行的解决方案。也许应该接受。