jQuery动态追加tr元素以及样式渲染

话不多说,直接上代码,^_^

<div data-options="region:'west',split:true" style="width:100%;">
    <table class="form_table" width="60%" style="margin-top: 15px; margin-left: 15px;">
        <tr>
            <td align="left" width="8%;" style="height:32px;" class="form_label">金额:</td>
            <td width="10%" style="height:32px;" class="form_data" colspan="2" align="left">
                <input name="je" class = "easyui-textbox" style="width:225px; height: 28px;"/>&nbsp;&nbsp;
                <a href="#" class="easyui-linkbutton c1"  iconCls="icon-add" onclick="addTr('form_table',-1);"></a> 
            </td>
        </tr>
    </table>
</div>

<script type="text/javascript">
    //动态添加tr
    function addTr(tab,row) {
       var trHtml="<tr>" +
            "<td align='left' width='5%;' style='height:32px;' class='form_label'>金额:</td>" +
            "<td align='left' width='10%' style='height:32px;' class='form_data' colspan='2' >" +
                "<input name='je1' class = 'easyui-textbox' style='width:225px;height: 28px;'/> " +
                "<a href='#' class='easyui-linkbutton'  iconCls='icon-remove' onclick='delTr(this);'></a>"+
            "</td>" +
        "</tr>";
        var $tr = $ ("."+tab+" tr").eq(row);
        if($tr.size() == 0){
           layer.confirm("指定的table id或行数不存在!!!");
           return;
        }

        $tr.after(trHtml);
        //渲染样式
        $.parser.parse('.form_table');
    }

    function delTr(obj) {
        layer.confirm("确认要删除当前行吗???", { time: 0 // 不自动关闭
            ,btn: ['确定','取消']
            ,yes: function(index){
                $(obj).parents("tr").remove();
                layer.close(index);
            }
        });
    }
</script>

效果图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值