• window.open打开新页面,并将本页数据用过url传递到打开的页面;需要两个页面;


    页面1

     1 <!doctype html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Document</title>
     6 </head>
     7 <body>
     8 <form action="">
     9     <div id="name1">
    10         <h1>哈哈</h1>
    11 
    12         <h2>嘿嘿嘿</h2>
    13 
    14         <p>呵呵呵呵呵呵呵呵呵呵</p>
    15     </div>
    16     <input id="value1" type="text" name="user.value" />
    17 </form>
    18 <button id="btn">点击</button>
    19 <script src = "http://libs.useso.com/js/jquery/1.8.3/jquery.min.js"></script>
    20 <script>
    21 
    22     $("#btn").click(function(){
    23         var a = {
    24             name : $("#name1").html(),
    25             value: $("#name1").val()
    26         };
    27         var b = JSON.stringify(a)
    28         var url ="1_1.html?"+b;
    29         window.open(url, 'newwindow', 'height=700, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')
    30     })
    31 
    32 
    33 </script>
    34 </body>
    35 </html>

    页面2

     1 <!doctype html>
     2 <html lang="en">
     3 <head>
     4     <meta charset="UTF-8">
     5     <title>Document</title>
     6 </head>
     7 <body>
     8 <h1>"hello word"</h1>
     9 <div id="div2">
    10 
    11 </div>
    12 <script src="http://libs.useso.com/js/zepto/1.1.1/zepto.min.js"></script>
    13 <script>
    14     $(function(){
    15         var url1 = location.search;
    16         if (url1.indexOf("?") != -1) {
    17             var url = url1.substr(1);
    18         }
    19         var jsondata = decodeURI(url);
    20         var data = JSON.parse(jsondata);
    21         $("#div2")[0].innerHTML = data.name;
    22 
    23     })
    24 </script>
    25 </body>
    26 </html>

    里面用到了,json的序列化与反序列化;JSON.parse()与JSON.stringify()

    还有一种传递数据的方法是通过document.write()直接将数据写入到新打开的页面;预览就是这么做的

    坚持下去就能成功
  • 相关阅读:
    一条Sql的Spark之旅
    Redis学习笔记:Redis在C#中的使用
    MySQL_表操作
    git上传新项目到coding
    Jenkins 安装 on centos7
    day 36
    表单生成器(Form Builder)之表单数据存储结构mongodb篇
    ORA-16032和ORA-07286 LOG_ARCHIVE_DEST_1没生效
    SQL查询小案例
    mysql从5.6升级到5.7后出现 Expression #1 of ORDER BY clause is not in SELECT list,this is incompatible with DISTINCT
  • 原文地址:https://www.cnblogs.com/suoking/p/4914901.html
Copyright © 2020-2023  润新知