This time I will show you how to make the browser jump and pass parameters, and what are the precautions for making the browser jump and pass parameters. The following is a practical case, let's take a look.
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>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Use JS to receive List
##Function throttling and time-sharing function use Detailed explanation of steps
The above is the detailed content of How to make the browser jump and pass parameters. For more information, please follow other related articles on the PHP Chinese website!