追影 发表于 2015-3-3 16:39:46

jquery动态追加表格行与删除行

<form action="{url:/goods/fangan_save/}" method="post">
                        <table class="form_table" cellpadding="0" cellspacing="0">
                       
                                <tr>
                                        <th>参数模型名称:</th>
                                        <td>
                                                <input class="normal" name="guige_name" type="text" value="{$item['guige_name']}" pattern="required" alt="名称不能为空" /><label>* 必选项</label>
                                                <input name="guige_id" value="{$item['guige_id']}" type="hidden" />
                                        </td>
                                </tr>
                {if:!isset($item['guige_arr'])}
                                <tr>
                                        <th>参数名:</th>
                                        <td><input class="normal" name="par[]" type="text" value="" /><label id="getAtr">追加参数</label></td>
                                </tr>
                {else:}
                <tr><th><label id="getAtr">追加参数</label></th><td></td></tr>
               {foreach:items = $item['guige_arr'] item=$vo}
                <tr>
                                        <th>参数名:</th>
                                        <td><input name="gd_id[]" type="hidden" value="{$vo}" /><input class="normal" name="par_{$vo}" type="text" value="{$vo}" /><button onClick="getDel(this)">删除参数</button></td>
                                </tr>
                {/foreach}
                {/if}
               
            <tbody id="addTr">   
            </tbody>
                                <tr>
                                        <td></td><td><button class="submit" type="submit"><span>确 定</span></button></td>
                                </tr>
                        </table>
                </form>
<script type='text/javascript'>
$(function(){   
    $("#getAtr").click(function(){         
      $str='';
      $str+="<tr>";
      $str+= '<th>参数名:</th>';
      $str+= '<td><input class="normal" name="par[]" type="text" value="" /><button onClick="getDel(this)">删除参数</button></td>';
      $str+="</tr>";
      $("#addTr").append($str);   
    });
});

function getDel(k){
    $(k).parent().parent().remove();   
}
</script>



Mypadaphone 发表于 2015-8-26 22:55:44

不错,不错

爱笑小猪猪 发表于 2015-10-13 10:45:57

恩啊不错不错。。。。
页: [1]
查看完整版本: jquery动态追加表格行与删除行