jquery实现增加删除行的方法

2020-05-23 06:09:04易采站长站整理

本文实例讲述了jquery实现增加删除行的方法。分享给大家供大家参考。具体分析如下:

最近做一个投票管理的模块,需要添加问题选项,为了方便,就简单地实现了表格行的添加、删除。

注:需引入jquery.js

先上效果图:(form中默认有4行)

表单代码:
<div class=”oz-form-fields”  style=”width:450px;padding-top: 5px”> 
    <table cellpadding=”0″ cellspacing=”0″ style=”width:450px;” id=”optionContainer”> 
        <tr id=”option0″>  
            <td class=”oz-form-topLabel”>所属问题 
                <c:if test=”${questionType==’radio’}”>(单选)</c:if> 
                <c:if test=”${questionType==’checkbox’}”>(复选)</c:if>: 
            </td> 
            <td class=”oz-property” > 
                ${question} 
            </td> 
            <td></td> 
        </tr> 
        <tr id=”option1″>  
            <td class=”oz-form-topLabel”>选项1:</td> 
            <td class=”oz-property” > 
                <input type=”text”  style=”width:300px”> 
            </td> 
            <td></td> 
        </tr> 
        <tr id=”option2″>  
            <td class=”oz-form-topLabel”>选项2:</td> 
            <td class=”oz-property” >