jQuery 浏览器之间跳转传递参数(支持中文字符)

来源:互联网 发布:网络营业执照图片 编辑:程序博客网 时间:2024/06/04 01:37
one.html
<!DOCTYPE html><html><head>    <meta charset="UTF-8">    <title></title>    <script src="https://cdn.bootcss.com/jquery/2.2.2/jquery.slim.js"></script></head><body><input type="text" class="keyword"/><button id="searchBtn">点击</button><script type="text/javascript">    $("#searchBtn").click(function() {        var searchText = jQuery.trim($(".keyword").val());        var searchUrl = encodeURI("two.html?searchText=" + searchText); //使用encodeURI编码          location.href = searchUrl;    })</script></body></html>
two.html

<!DOCTYPE html><html><head>    <meta charset="UTF-8">    <title></title>    <script src="https://cdn.bootcss.com/jquery/2.2.2/jquery.slim.js"></script></head><body><input type="text" class="keyword1"/><script type="text/javascript">    //获取 上一个搜索页面传来的参数      var searchUrl = window.location.href;    var searchData = searchUrl.split("="); //截取 url中的“=”,获得“=”后面的参数      var searchText = decodeURI(searchData[1]); //decodeURI解码      $(".keyword1").val(searchText);</script></body></html>

原创粉丝点击