将此javascript函数转换为jquery

时间:2011-03-17 19:50:03

标签: javascript jquery

有人可以转换这个普通的javascript函数来使用jquery函数吗?谢谢!

move_object = function (from, to) {
    var i, // local variable
    childnodes_length; // number of child nodes 
    // test if "from" cell is equal to "to" cell then do nothing
    if (from === to) {
        return;
    }
    // define childnodes length before loop (not 
    // in loop because NodeList objects in the DOM are live)
    childnodes_length = from.childNodes.length;
    // loop through all child nodes
    for (i = 0; i < childnodes_length; i++) {
        // '0', not 'i' because NodeList objects in the DOM are live
        to.appendChild(from.childNodes[0]); 
    }
};

1 个答案:

答案 0 :(得分:3)

这应该这样做:

$(from).contents().appendTo(to);

现场演示: http://jsfiddle.net/simevidas/YxcYC/