将一个html(引导程序)表的数据附加到另一个引导程序表

时间:2015-08-27 13:12:52

标签: javascript html css twitter-bootstrap

我写了一个bootstrap UI,如下面的屏幕截图所示:
img
Code is as shown here. 当用户点击新订单表中的接受按钮时,food 1应移至accepted表。我该怎么做?我的代码不工作。
Javascript:

function append() {
        // Code...
        if (!('#btnOne').onclick) {
            var htmlrows = "";
            var htmltablestart = '<table class="table table-hover borderless">';
            htmlrows = htmlrows + '<tr><td>' + foodOne + '</td><td class="pull-right"> <button type="button" class="btn btn-primary" onclick="appendComplete();" id="btnThree">Completed</button> </td><td></tr>';
            var htmltableend = '</table>';
            var htmlTable = htmltablestart + htmlrows + htmltableend;
            ('#acceptedOrdrDiv').append(htmlTable);
            alert('you have accepted the order');
        } else {
            alert('you have not accepted the order');
        }
    }
    function appendComplete() {
        // Code...
        if (!('#btnThree').onclick) {
            var htmlrows = "";
            var htmltablestart = '<table class="table table-hover borderless">';
            htmlrows = htmlrows + '<tr><td>' + foodOne + '</td></tr>';
            var htmltableend = '</table>';
            var htmlTable = htmltablestart + htmlrows + htmltableend;
            ('#completedOrdrDiv').append(htmlTable);
            alert('you have completed the order');
        } else {
            alert('you have not completed the order');
        }
    }  

我还希望在点击new order按钮时删除Accept表中的已接受订单。

1 个答案:

答案 0 :(得分:1)

HTML:

<div id="acceptedOrdrDiv" class="panel-body" style="overflow-y: auto; height: 90%;">
    <table class="table table-hover borderless accepted-orders">
    </table>
</div>

JQuery的:

$('.btn.btn-primary').click(function () {
    var text = $(this).parent().parent().children().filter(':first-child');
    var thisTr = text.parent();
    console.log($('.table.accepted-orders'));
    $('.table.accepted-orders').append('<tr><td>'+text.text()+'</td><td class="pull-right"><button type="button" class="btn btn-primary">Completed</button></td>');
    thisTr.remove();
});