在页面之间传输HTML数据

时间:2016-11-24 16:49:55

标签: html

一段时间以来一直非常紧张,因为我对编码很新,并且无法弄清楚如何跨页面传输一些段落数据。 这是我的第一页上的代码:

    <!DOCTYPE>
    <html>
    <head>
    <h1>z</h1>
    </head>
    <body>
    <p>test</p>
    <p id="goalPage"></p>
    <script type="text/javascript">
    var t = Math.floor((Math.random() * 1) + 1);
    if (t === 1) {document.getElementById("goalPage").innerHTML = "Your goal page is Data 1";}
    else {alert('Unprecedented failure. Please reload the page and report   the bug to me.');}
    function testJS() {
    var b = document.getElementById('goalPage').value,
    url = 'file:///C:/Users/Admin/Desktop/Coding%20Data%20Files/data1.html?name=load' + encodeURIComponent(b);

    document.location.href = url;
    }
    </script>

在我的第二页上,这是我的代码:

    <!DOCTYPE>
    <html>
    <head>
    <h1>w</h1>
    </head>
    <body>
    <p id="goalPage"></p>
    <script>
    window.onload = function () {
    var url = document.location.href,
    params = url.split('?')[1].split('&'),
    data = {}, tmp;
    for (var i = 0, l = params.length; i < l; i++) {
     tmp = params[i].split('=');
     data[tmp[0]] = tmp[1];
    }
    document.getElementById('goalPage').innerHTML = data.load;
    }
    </script>
    </body>
    </html>

我使用了许多其他论坛的答案来尝试获得有效的解决方案,但我无法做到。任何帮助将不胜感激。

0 个答案:

没有答案
相关问题