1

ループから生成されたクリック可能な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);
                });
    });
}
}
4

2 に答える 2

0

現在のウィンドウから作成された子ウィンドウで直接実行するだけです。

于 2013-01-18T11:37:21.190 に答える
-1

これが私が探していた解決策です。これにより、個人の userDiv に直接関連するグローバル var 名が得られます。

     userDiv.id=theName;
        userDiv.onclick=(function() {
            window.location.href = 'Createtask.html';
            alert($(this).attr("id"));
            name= $(this).attr("id");
于 2013-01-18T14:58:26.580 に答える