a链接传参的方法

   //获取分案编号
var hrefVal=window.location.href.split("?")[1]; //得到id=楼主
//console.log(hrefVal+"后一个"+hrefVal[3]);
var theRequest = new Object();
var strs = hrefVal.split( "&" );
//那么我们在新页面接收参数, 并且将参数转为可用的json格式时, 可以用下面的方法:
for ( var i = 0; i < strs.length; i++ ) {
theRequest[ strs[ i ].split( "=" )[ 0 ] ] = ( strs[ i ].split( "=" )[ 1 ] );
}
console.log( theRequest );
var division_code = $("#division_code span").html(theRequest.assignNo);
//那么我们在新页面接收参数, 并且将参数转为可用的json格式时, 可以用下面的方法:
// var url = location.search; //获取url中"?"符后的字串 ('?modFlag=business&role=1')
// var theRequest = new Object();
// if ( url.indexOf( "?" ) != -1 ) {
// var str = url.substr( 1 ); //substr()方法返回从参数值开始到结束的字符串;
// var strs = str.split( "&" );
// for ( var i = 0; i < strs.length; i++ ) {
// theRequest[ strs[ i ].split( "=" )[ 0 ] ] = ( strs[ i ].split( "=" )[ 1 ] );
// }
// console.log( theRequest ); //此时的theRequest就是我们需要的参数;
posted @ 2018-05-28 17:08  追梦的老头  阅读(2232)  评论(0编辑  收藏  举报