html页面跳转传递参数
来源:互联网 发布:node v6.11.1 x64.msi 编辑:程序博客网 时间:2024/05/19 12:40
从a.html跳转到b.html页面,如果给b.html传递参数,可以通过下面的方式来传递:
- 直接将参数拼接到url上,如b.html?param1=aa¶m2=bb
- 通过正则表达式解析参数
a页面代码:
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>A页面</title></head><body> <div>这是A页面</div> <div> <!-- 参数直接拼接到url上 --> <a href="b.html?param1=aa¶m2=bb">访问b页面</a> </div></body></html>
b页面代码:
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>B页面</title></head><body> <div>这是B页面</div> <script type="text/javascript"> function getParams(key) { var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) { return unescape(r[2]); } return null; }; console.log("参数param1:"+getParams("param1"));//输出aa console.log("参数param2:"+getParams("param2"));//输出bb </script></body></html>
getParams方法说明:
- window.location.search为url中参数部分,包括?,如果url为http://localhost/b.html?name=aa&age=20,那么window.location.search的值为 ?name=aa&age=20
- 创建正则表达式,以key开头(如name=aa),或者key前面包含&,并且值的最后有&或直接是末尾,并且值中不包含&。
0 0
- html页面跳转传递参数
- html页面跳转传递参数
- html页面跳转及参数传递
- 跳转页面传递参数
- html两个页面跳转时传递参数location.search
- html中如何在页面跳转中传递参数
- Android 页面跳转 传递参数
- thinkphp 页面跳转传递参数
- angular-页面跳转传递参数
- vue页面跳转参数传递
- HTML页面间传递参数
- HyperLink跳转页面传递绑定参数
- LinkButton跳转页面传递绑定参数
- 页面跳转,传递中文参数的方法
- jquerymobile页面跳转和参数传递
- SilverLight页面跳转及参数传递
- JQueryMobile页面跳转参数的传递解决方案
- jquerymobile页面跳转和参数传递
- Servlet制作验证码
- 第11章 WebSocket协议开发
- LeetCode学习篇二十五——Balanced Binary Tree
- Javascript: unterminated string literal 解决方法
- axis2系列之返回json数据
- html页面跳转传递参数
- 批量修改文件名
- 数据结构试验四 --图论
- Java多线程锁对象的改变
- JS唤醒Android APP(包括在外部浏览器和WebView)
- Java基础第一阶段——02_Java语言基础_关键字&变量&运算
- 最短路径——SPFA算法(蓝桥杯试题集)
- java基础-集合框架9 增强for循环
- 带外数据