zoukankan      html  css  js  c++  java
  • 案例:获取URL参数数据

    主要实现的是数据在不同页面中的传递功能

    ① 第一个登录页面,里面有提交表单,action提交到index.html页面

    ② 第二个页面,可以使用第一个页面的参数,这样实现了一个数据不同页面之间的传递效果

    ③ 第二个页面之所以可以使用第一个页面的数据,是利用了URL里面的location.search参数

    ④ 在第二个页面中,需要把这个参数提取出来

    ⑤ 第一步:去掉 '?' ,利用substr

    ⑥ 第二步:利用=号分割键和值,利用split('=')

    <!-- 登录页面布局 -->
    <body>
        <form action="index.html">
            用户名:<input type="text" name="uname">
            <input type="submit" value="登录">
        </form>
    </body>
    <!-- index.html页面接收登录传过来的信息 -->
    <script>
        console.log(location.search);  // ?uname=andy
        // 1. 先去掉问号?  substr('起始的位置', 截取几个字符串);
        var params = location.search.substr(1);  // uname=andy
        console.log(params);
        // 2. 利用等号=把字符串分割为数组split('=');
        var arr = params.split('=');
        console.log(arr);  // ["uname", "andy"]
        var div = document.querySelector('div');
        // 3. 把数据写入div中‘
        div.innerHTML = arr[1];
    </script>
  • 相关阅读:
    python 的class和def 定义执行语句相关
    python _和__ 下划线命名规则
    python2和python3编码问题【encode和decode】
    cpython源码阅读
    eCPRI
    python内存管理/垃圾回收
    Class() vs self.__class__()
    JAVA学习日报 11/24
    JAVA学习日报 11/23
    JAVA学习日报 11/22
  • 原文地址:https://www.cnblogs.com/zcy9838/p/12952686.html
Copyright © 2011-2022 走看看