复制表行并将其粘贴到该行的下方 [英] Copy Table Row And Paste it Below Of that Row

查看:89
本文介绍了复制表行并将其粘贴到该行的下方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hey Can AnyOne告诉我如何使用Inclue复制表行所有Asp.Net控件具有值并粘贴到复制行下面的行???

Hey Can AnyOne Tell Me That How To Copy Table Row With Inclue All Asp.Net Controls Having Values And Paste That Row Below Of Copied Row ???

推荐答案

您好,假设您需要复制一个html表格行及其中的控件(元素)。



相同的功能在这里发布.. http://jsfiddle.net/2NJrd/ [ ^ ]



检查一次..
Hello, assumed that you need to copy a html table row along with the controls(elements) inside it.

the same functionality is posted here..http://jsfiddle.net/2NJrd/[^]

check once..


嗨..检查解决方案这里。 http://jsfiddle.net/NVCMQ/ [ ^ ]
Hi.. check the solution here. http://jsfiddle.net/NVCMQ/[^]


这里有一些代码可以达到我想要的效果。

缺点是附加事件也没有附加到dupliacate行。也就是说,单击一行将复制它并在单击的行下面添加一个副本。不幸的是,您必须手动附加onclick处理程序才能复制副本。 (我不知道)也许有一种方法可以迭代对象的处理程序,以便将它们复制到另一个对象。



当然,这可能不需要。作为猜测,具有内联处理程序的元素可以正常工作。



例如



我想以下会复制得很好

Here's some code that will achieve what I think you want.
The drawback is that attached events are not also attached to the dupliacate row. That is to say, clicking a row will duplicate it and add a copy below the clicked row. Unfortunately, you'll have to manually attach the onclick handler in order to be able to copy a copy. (I dont know) Perhaps there's a way of iterating through the handlers of an object in order to copy them to another.

Of course, this may not be needed. As a guess, elements with inline handlers would work ok.

E.g

I imagine that the following would duplicate just fine
<button  önclick="doSomethingFunc();">Do Something</button>





虽然以编程方式附加处理程序的方法似乎不会重复处理程序。



While an approach that attaches the handlers programatically appears not to duplicate the handlers.

HTML:
<button id="doSomethingBtn">Do Something</button>

Javascript:
document.getElementById('doSomethingBtn').addEventListener(click, doSomethingFunc, false);













<!DOCTYPE html>
<html>
<head>
<script>
function byId(e){return document.getElementById(e);}
function newEl(tag){return document.createElement(tag);}
function newTxt(txt){return document.createTextNode(txt);}
function toggleClass(element, newStr)
{
    index=element.className.indexOf(newStr);
    if ( index == -1)
        element.className += ' '+newStr;
    else
    {
        if (index != 0)
            newStr = ' '+newStr;
        element.className = element.className.replace(newStr, '');
    }
}
function forEachNode(nodeList, func)
{
    var i, n = nodeList.length;
    for (i=0; i<n; i++)
    {
        func(nodeList[i], i, nodeList);
    }
}

window.addEventListener('load', mInit, false);

function makeTable(nCols, nRows, idTxt)
{
    var x, y, curRow, curCell, tbl = newEl('table');
    tbl.setAttribute('id', idTxt);
    for (y=0; y<nRows; y++)
    {
        curRow = tbl.insertRow();
        curRow.addEventListener('click', onRowClick, false);
        for (x=0; x<nCols; x++)
        {
            curCell = curRow.insertCell();
            curCell.innerHTML = "Cell: " + (nCols-x) + "," + (nRows-y);
        }
    }
    return tbl;
}

function insertAfter(node, reference)
{
    // If the reference node has a nextSibling, insert
    // the node before that
    if (reference.nextSibling)
    {
    reference.parentNode.insertBefore(node,reference.nextSibling);
    // If the reference node is the last child, just
    // append the node to the parent
    }

    else {
    reference.parentNode.appendChild(node);
    }
    return node;
}

function onRowClick(e)
{
    var curRow = this;
    var duplicatedRow = curRow.cloneNode(true);

    duplicatedRow.cells[0].innerHTML = duplicatedRow.cells[0].innerHTML + "(copied)";
    insertAfter(duplicatedRow, curRow);
}

function mInit()
{
    var tbl = makeTable(10, 5, 'dynTable');
    document.body.appendChild(tbl);
}

</script>
<style>
</style>
</head>
<body>
</body>
</html>


这篇关于复制表行并将其粘贴到该行的下方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆