2013-01-18 28 views
1

我有一个循环生成的可点击的div。我试图设置它,以便onclick它自己附加到另一个页面上的另一个div。这可能吗。这是我尝试过的。我可以通过一个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); 
       }); 
    }); 
} 
} 
+0

可能但毫无意义... –

+2

这是一个什么样的问题呢?尝试一下,看看会发生什么。 – Amberlamps

+1

@Amberlamps *“...这是我所尝试过的。”*所以看起来OP已经尝试了代码,但无法使其工作。 – Yoshi

回答

0

你仅仅只做到这一点直接与子窗口,从当前窗口创建。

+0

嗨Trung,你的意思是我应该链接到页面而不是打开新窗口? – Inkers

+0

嗨Inkers,你只是控制你从代码打开的窗口。你不能通过链接控制其他窗口:) –

+0

好吧,我超级困惑。时间走开,做一些阅读我想。 – Inkers

-1

这是我正在寻找的解决方案。这给了我一个与用户的userDiv直接相关的全局变量名称。

 userDiv.id=theName; 
     userDiv.onclick=(function() { 
      window.location.href = 'Createtask.html'; 
      alert($(this).attr("id")); 
      name= $(this).attr("id"); 
相关问题