------------------*/
}catch(e){
console.error("执行出错,错误信息: " + e);
}
练习3:
实现一个URI解析方法,把url里#之后的参数解析成指定的数据结构。
function urlParser(s){
//+++++++++++答题区域+++++++++++
//+++++++++++答题结束+++++++++++
}
try{
var url1 = "#page/2/?type=latest_videos&page_size=20";
var url2 = "#type=latest_videos&page_size=20";
var url3 = "#page?type=latest_videos&page_size=20";
console.group();
console.info( urlParser(url1) );
console.info( urlParser(url2) );
console.info( urlParser(url3) );
console.groupEnd();
/*------[执行结果]------
["page", "2", { "type": "latest_videos", "page_size": 20 }]
[{ "type": "latest_videos", "page_size": 20 }]
["page", { "type": "latest_videos", "page_size": 20 }]
------------------*/
}catch(e){
console.error("执行出错,错误信息: " + e);
}