原文:https://www.cnblogs.com/chensihan/p/6812678.html
效果如下:
a页面
点击跳转按钮后
在b页面可以获取到对应的值。
代码如下:
a页面:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <script src="js/jquery-3.0.0.min.js"></script> <script src="js/jquery.params.js"></script> <title>a页面</title> <script> $(function(){ name = $("#name").text(); age = $("#age").text(); $("#btn").on("click",function(){ jump1(); }); }); function jump1(){ url = "b.html?name="+name+"&age="+age;//此处拼接内容 window.location.href = url; } </script> </head> <body> <div id="name">tony</div> <div id="age">23</div> <button id="btn">跳转</button> </body> </html>
将要跳转到的b页面:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <script src="js/jquery-3.0.0.min.js"></script> <script src="js/jquery.params.js"></script> <title>b页面</title> <script> $(function(){ getData1(); }); function getData1(){ var name = $.query.get("name"); var age = $.query.get("age"); $("#name").text(name); $("#age").text(age); } </script> </head> <body> <div id="name"></div> <div id="age"></div> </body> </html>