📌  相关文章
📜  在Javascript代码示例中将数据从一个页面发送到另一个html页面

📅  最后修改于: 2022-03-11 15:01:19.399000             🧑  作者: Mango

代码示例1
//use this in page one
//where you will send data from
function testJS() {
    var b = document.getElementById('name').value,
        url = 'http://path_to_your_html_files/next.html?name=' + encodeURIComponent(b);

    document.location.href = url;
}
//use the following code where you want to receive data
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('here').innerHTML = data.name;
}