zoukankan      html  css  js  c++  java
  • 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>

    效果

  • 相关阅读:
    VMware安装Centos7过程记载
    php服务器设置指示
    php变化变量
    php参数
    php变量类型
    php外界PHP变量
    php语句的脱离方法
    PHP算术操作符
    PHP通过调用传递(Passingbyreference)
    php初始化数组
  • 原文地址:https://www.cnblogs.com/chenluomenggongzi/p/6040659.html
Copyright © 2011-2022 走看看