页面传递参数
登录页面 login
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>登录页面</title> </head> <body> <form action="index.html" method="get"> <input type="text" name="user"> <input type="submit" value="登录"> </form> </body> </html>
接收页面 index
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>index</title> </head> <body> <div></div> <script> // 1 先去掉问号 substr var params = location.search.substr(1); console.log(params); // user=libai // 2 通过等号分割字符串 var arr = params.split('='); console.log(arr);// ["user", "libai"] //取出值赋值给页面上 var div = document.querySelector('div'); div.innerHTML = arr[1] + '欢迎您'; </script> </body> </html>