Url是这样生成的
/Home/LoadData?page=2&activeTab=House
如何获取 activeTab 值?
function getURLParameter(name) {
return decodeURI(
(RegExp(name+ '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
);
}
并将其称为getURLParameter('activeTab');
请在您的 javascript 中添加此功能
你可以传递参数名称,你可以获得价值
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
希望对你有帮助。
您可以使用 javascriptsubstr()
和.lastIndexOf()
:
var url = '/Home/LoadData?page=2&activeTab=House'; // window.location.href;
var activeTab = url.substr(url.lastIndexOf('=')+1); // outputs House
尝试这样的事情
$(document).ready(function(){
var url = 'http://stackoverflow.com/Home/LoadData?page=2&activeTab=House';
alert(decodeURI(
(RegExp('activeTab=' + '(.+?)(&|$)').exec(url)||[,null])[1]
));
});