Url就是这样生成的
/Home/LoadData?page=2&activeTab=House
如何获取activeTab值?
答案 0 :(得分:3)
function getURLParameter(name) {
return decodeURI(
(RegExp(name+ '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
);
}
并将其称为getURLParameter('activeTab');
答案 1 :(得分:2)
请在您的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, " "));
}
希望对你有帮助。
答案 2 :(得分:1)
答案 3 :(得分:1)
您可以使用javascript的substr()
和.lastIndexOf()
:
var url = '/Home/LoadData?page=2&activeTab=House'; // window.location.href;
var activeTab = url.substr(url.lastIndexOf('=')+1); // outputs House
答案 4 :(得分:1)
尝试这样的事情
$(document).ready(function(){
var url = 'http://stackoverflow.com/Home/LoadData?page=2&activeTab=House';
alert(decodeURI(
(RegExp('activeTab=' + '(.+?)(&|$)').exec(url)||[,null])[1]
));
});