location.href location href 頁面 傳遞 參數 而且 接收 简体版
原文   原文鏈接
<span style="font-size:18px;">能夠直接使用window.location.href進行頁面跳轉  
window.location.href = "./punch/clock_frm.html"  
問號傳參:  
window.location.href = "./punch/clock_frm.html?modFlag="+modFlag+'&role='+role;  
  
那麼咱們在新頁面接收參數, 而且將參數轉爲可用的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就是咱們須要的參數;  
}</span>  

location.href傳參中文亂碼問題解決

在js中經過window.location.href方式跳轉頁面並在路徑上傳遞參數中文亂碼解決
js中對中文進行編碼:(不對ASCII 字母和數字進行編碼)
window.location.href = ‘aaa.html?Unit=’+encodeURI(encodeURI(中文內容))
//有時須要兩次編碼
window.location.href = ‘aaa.html?Unit=’+encodeURI(中文內容)
//有時只須要編碼一次便可(具體緣由沒有細究)

在接收頁面接收的時候再解碼回來便可
decodeURI(window.location.href)
--------------------- 
版權聲明:本文爲CSDN博主「qq_42833778」的原創文章,遵循CC 4.0 by-sa版權協議,轉載請附上原文出處連接及本聲明。
原文連接:https://blog.csdn.net/qq_42833778/article/details/83621829
相關文章
相關標籤/搜索
每日一句
    每一个你不满意的现在,都有一个你没有努力的曾经。
本站公眾號
   歡迎關注本站公眾號,獲取更多信息