Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript DOM克隆节点_Dom_Javascript Events - Fatal编程技术网

使用Javascript DOM克隆节点

使用Javascript DOM克隆节点,dom,javascript-events,Dom,Javascript Events,我想使用JavaScriptDOM为下面的代码创建一个克隆 var summaryDiv = __createElement("div","sDiv","sDiv"+j); summaryDiv.onmouseover = function() {this.setAttribute("style","text-decoration:underline;cursor:pointer;");} summaryDiv.onmouseout = function() {

我想使用JavaScriptDOM为下面的代码创建一个克隆

 var summaryDiv = __createElement("div","sDiv","sDiv"+j);
        summaryDiv.onmouseover = function() {this.setAttribute("style","text-decoration:underline;cursor:pointer;");}
        summaryDiv.onmouseout = function() {this.setAttribute("style","text-decoration:none;");}
        if(browser.isIE) {
            summaryDiv.onclick = new Function("__fc.show_tooltip("+j+",'view_month')");
    } else {
            summaryDiv.setAttribute("onclick", "__fc.show_tooltip("+j+",'view_month',event)");
        }
   someobj.appendChild(summaryDiv);
我正在使用obj=summaryDiv.cloneNode(true),它正在创建节点。但在Internet Explorer的情况下,onclick事件并没有引发火灾。有人能帮我解决这个问题吗

this.setAttribute("style","text-decoration:underline

不要使用setAttribute,它在IEB中不起作用,而不使用setAttribute('onclick'),为什么不将一个函数分配给onclick属性?我正在使用循环创建多个div,并使用setAttribute分配一些值,我正在将这些值传递到show_工具提示函数中。我已经尝试分配事件(onclick)我的意思是,我可以看穿IE8中的web开发者工具,事件(onclick)是为该元素设置的,但它没有启动。我想分享的另一个细节是,在我的程序中,克隆和旧对象都存在于文档中,内部元素具有相同的id…请帮助我,我只是对它感到困惑,请发布新代码!(例如,pastebin.com等)如果您有重复的ID,那么按ID检索元素肯定会有困难。
    if(browser.isIE) {
        summaryDiv.onclick = new Function("__fc.show_tooltip("+j+",'view_month')");
    } else {
        summaryDiv.setAttribute("onclick", "__fc.show_tooltip("+j+",'view_month',event)");
    }
summaryDiv.onclick= function() {
    __fc.show_tooltip(j, 'view_month');
};
summaryDiv.onclick= __fc.show_tooltip.bind(__fc, j, 'view_month');
newClone.onclick= oldNode.onclick;