本文纯属个人成长道路记录,如有错误,请大牛多多指点。
a标签代码块(可携带多个型参)
<a href='caseCode.html?indexPage3Id=1'>
获取a标签?后携带的参数,并返回集合,同时传递给ifIndexPage3Id函数。
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
}
}
ifIndexPage3Id(theRequest);
}
进行判断是否存在默认值,没有则赋予一个
function ifIndexPage3Id(theRequest) {
//第一种处理方式
var id = theRequest["indexPage3Id"];//接收indexPage3Id参数
console.log({}.toString.call(id));
if(typeof(id) == "undefined" || "" == id || null == id){//判断是否为undefined、空、null
id = "1";//如果是则给一个默认值,我这给的1。
}
if(id == "1"){
//根据需求编写代码
}else if (id == "2"){
//根据需求编写代码
}
}
后续根据自己需求编写