js解码
如代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <input type="text" id="input"> <button id="btn">click to html</button> <script> var btn=document.getElementById("btn"); var int=document.getElementById("input"); btn.onclick=function () { open("others.html?"+int.value); } </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script> document.body.innerHTML=location.search.replace("?",""); </script> </body> </html>
结果图;
search数据正常传入
当是中文的时候则
数据乱码
修改代码为
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 <input type="text" id="input"> 9 <button id="btn">click to html</button> 10 <script> 11 var btn=document.getElementById("btn"); 12 var int=document.getElementById("input"); 13 btn.onclick=function () { 14 var val=encodeURIComponent(int.value); 15 open("others.html?"+val+""); 16 console.log(val); 17 } 18 </script> 19 </body> 20 </html>
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 <script> 9 document.body.innerHTML=decodeURIComponent(location.search).replace("?",""); 10 </script> 11 </body> 12 </html>
效果
myGitgub https://github.com/mfx55
希望我的博客能帮到你