window.location.href傳參/傳值匯總


找了網上的幾種版本(做個筆記匯總)

One:(https://www.cnblogs.com/weimingxin/p/6773881.html)

 

 Two:(https://blog.csdn.net/weixin_43496408/article/details/103479735)

 

 Three:(https://blog.csdn.net/qq_42833778/article/details/83621829)

 1 <span style="font-size:18px;">可以直接使用window.location.href進行頁面跳轉  
 2 window.location.href = "./punch/clock_frm.html"  
 3 問號傳參:  
 4 window.location.href = "./punch/clock_frm.html?modFlag="+modFlag+'&role='+role;  
 5   
 6 那么我們在新頁面接收參數, 並且將參數轉為可用的json格式時, 可以用下面的方法:  
 7 var url = location.search; //獲取url中"?"符后的字串 ('?modFlag=business&role=1')  
 8 var theRequest = new Object();  
 9 if ( url.indexOf( "?" ) != -1 ) {  
10   var str = url.substr( 1 ); //substr()方法返回從參數值開始到結束的字符串;  
11   var strs = str.split( "&" );  
12   for ( var i = 0; i < strs.length; i++ ) {  
13     theRequest[ strs[ i ].split( "=" )[ 0 ] ] = ( strs[ i ].split( "=" )[ 1 ] );  
14   }  
15   console.log( theRequest ); //此時的theRequest就是我們需要的參數;  
16 }</span>

-----------中文亂碼問題----------

 1 在js中通過window.location.href方式跳轉頁面並在路徑上傳遞參數中文亂碼解決
 2 js中對中文進行編碼:(不對ASCII 字母和數字進行編碼)
 3 window.location.href = ‘aaa.html?Unit=’+encodeURI(encodeURI(中文內容))
 4 //有時需要兩次編碼
 5 window.location.href = ‘aaa.html?Unit=’+encodeURI(中文內容)
 6 //有時只需要編碼一次即可(具體原因沒有細究)
 7 
 8 在接收頁面接收的時候再解碼回來即可
 9 decodeURI(window.location.href)
10 --------------------- 
11 版權聲明:本文為CSDN博主「qq_42833778」的原創文章,遵循CC 4.0 by-sa版權協議,轉載請附上原文出處鏈接及本聲明。
12 原文鏈接:https://blog.csdn.net/qq_42833778/article/details/83621829

Four:

 

Five:(https://blog.csdn.net/qq_37418745/article/details/78758280)

 

 

 -------學習正則表達式------

>>>>>>https://www.runoob.com/regexp/regexp-syntax.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM