页面之间的普通跳转,也就是a标签href的值,但是有些时候,仅仅用href的值是不行的,比方说:
1.从当前页面(index.html)跳转到另一页面(person-center.html)的某一部分(首页跳转到个人中心的个人资料当中)。
2,从当前页面跳转到另一页面,另一页面的某个部分的显示和隐藏。
首先(1):在index.html页面中是需要带有参数的js跳转——
window.location.href="person-center.html?type=2";
在person-center.html需要接受参数,那么在这个页面上$(function(){})之外先写一个方法:
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
}
然后再判断参数值:
在判断之前要在$(function(){})内部,调用一个getQueryString()这个方法
var type = getQueryString("type");
if(type==null || type==""){
//没有参数
}else if(type=="2"){
//有参数 说明是跳转过来的
//如果type类型为2,
//那么也就是跳转到个人中心的my-faqi-pro.html的部分,显示在右侧的iframe当中
$("#iframepage").attr("src","my-faqi-pro.html");
}else if(type=="3"){
//如果type类型为3,
//那么也就是跳转到个人中心的trading-details.html的部分,显示在右侧的iframe当中
$("#iframepage").attr("src","trading-details.html");
}else if(type=="6"){
//如果type类型为6,
//那么也就是跳转到个人中心的my-message.html的部分,显示在右侧的iframe当中
$("#iframepage").attr("src","my-message.html");
}
同理(2):
在接受参数的页面当中也写上getQueryString()这个方法,同样的调用getQueryString()这个方法判断没有参数,如果有参数的话,控制显示或者隐藏。