Jquery从MVC url获取参数Id?

我有以下url: http : //www.xzy.com/AMS/Audit/Agency/10017397

我需要从这个url中删除id:10017397?

我试过了:

function GetURLParameter(sParam) { var sPageURL = window.location.search.substring(1); var sURLVariables = sPageURL.split('&'); for (var i = 0; i < sURLVariables.length; i++) { var sParameterName = sURLVariables[i].split('='); if (sParameterName[0] == sParam) { return sParameterName[1]; } } } 

这将有助于您了解演示

 function GetURLParameter() { var sPageURL = window.location.href; var indexOfLastSlash = sPageURL.lastIndexOf("/"); if(indexOfLastSlash>0 && sPageURL.length-1!=indexOfLastSlash) return sPageURL.substring(indexOfLastSlash+1); else return 0; } 

您可以尝试使用此正则表达式从字符串中获取最后一个数字: http : //jsfiddle.net/2AKDQ/2/

 var URL = "http://www.xzy.com/AMS/Audit/Agency/10017397"; var number = URL.match(/(\d+)$/g); 

但是你真的需要提供更多的信息。数值是否总是在字符串的末尾? 或者如果没有,它总是在第4位吗? 字符串总是与数字相同吗?

在这里你去它只提取字符串中的数字

 var thestring="http://www.xzy.com/AMS/Audit/Agency/10017397"; your_required_no= thestring.match(/\d+\.?\d*/g) alert(your_required_no) 

如果你确定你的url只有最后一个后的数字/然后尝试上面的数字