javascript - 我可以将 div 及其内容传递到另一个页面吗

标签 javascript

我有一个从循环生成的可点击的div。我正在尝试对其进行设置,以便 onclick 将其自身附加到不同页面上的另一个 div 中。这可能吗。这是我尝试过的。

     userDiv.addEventListener("click",
            function () {
                var one = document.getElementById('userDiv');
                var two = document.getElementById('singleUser');
                two.appendChild(one);
                window.open("Createtask.html");
     }

编辑这里是所有代码

   var theID;
    var theName;
    var thePhoto;
    var len = results.rows.length;
    console.log(len);
    for (var i = 0; i < len; i++) {
        theID = results.rows.item(i).id;
        console.log(theID);
        theName = results.rows.item(i).username;
        var htmlStr = theName;
        console.log(theName);
        thePhoto = results.rows.item(i).imagepath;
        console.log(thePhoto);

        var imageHold = new Image();
        imageHold.src = thePhoto;
        console.log("this is the src:" + imageHold.src);
        var userDiv = document.createElement("div"); //Create the div
        userDiv.innerHTML = htmlStr;
        userDiv.appendChild(imageHold);
        imageHold.width = 100;
        imageHold.height = 100;
        document.getElementById('showUsers').appendChild(userDiv); //append it to the document
        userDiv.style.display = 'block';


        identity = results.rows.item(i).username;
        userDiv.id = identity;
        console.log(identity);
        userDiv.addEventListener("click",

            function () {
                var w = window.open("Createtask.html");
                w.addEventListener("load", function(){
                  var one = document.getElementById('userDiv');
                  var two = w.document.getElementById('singleUser');
                  two.appendChild(one);
                });
    });
}
}

最佳答案

您只需直接使用从当前窗口创建的子窗口即可。

关于javascript - 我可以将 div 及其内容传递到另一个页面吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14398090/

相关文章:

javascript - 还记得刷新后使用 jQuery 切换状态吗?

javascript - 在 redux-observable 中使用 rxjs 示例来监听其他操作

javascript - 下拉菜单和子菜单的背景色

javascript - 如何将容器的高度设置为视口(viewport)高度减去 300 像素的高度 slider ?

javascript - 在 JavaScript 中,如果 key 是一个对象,为什么 object[key] 不等于 key?

javascript - XMLHttpRequest/ajax 设置内容类型

javascript - 加载页面时的 jQuery 窗口位置

javascript - .html() 、 innerHTML() 和 .text() 不更改文本

javascript - 使用 casperjs 提交表单 - 新 url 不加载

javascript - 如何在页面加载之前运行 JavaScript 代码?