1 需求
CSS | JS | PHP | |
id属性 | YES | YES | |
class属性 | YES | YES | |
name属性 | YES | YES |
2 语法
3 示例
test1.php
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8"/>
- <title></title>
- <style>
- h1 {
- text-align: center;
- }
- </style>
- <script>
- function locationHref() {
- location.href = "http://localhost/LearnMore/test2.php?p2=123";
- }
-
- function locationAssign() {
- location.assign("http://localhost/LearnMore/test2.php?p3=123");
- }
- </script>
- </head>
- <body>
- <!-- get请求传参四种方式:form表单、a标签 href属性、location对象 href属性、location对象 assign方法 -->
- <h1>GET请求传参方式一:form表单</h1>
- <form action="test2.php">
- <input type="password" name="password" placeholder="Please input your password"/>
- <button type="submit">Login</button>
- </form>
- <hr>
- <h1>GET请求传参方式二:a标签 href属性</h1>
- <a href="http://localhost/LearnMore/test2.php?p1=123">a标签 href属性</a>
- <hr>
- <h1>GET请求传参方式三:location对象 href属性</h1>
- <button type="button" onclick="locationHref()">location.href</button>
- <hr>
- <h1>GET请求传参方式四:location对象 assign方法</h1>
- <button type="button" onclick="locationAssign()">location.assign</button>
- </body>
- </html>
- </!DOCTYPE>
test2.php
-
- header('Content-Type: text/html;charset=utf-8');
-
- echo '
'
; -
- var_dump($_GET);
4 参考资料