删除所有信息或删除行

时间:2015-12-14 02:34:16

标签: javascript

我的JAVASCRIPT代码:

var a1=1;

function addst(data)
{
    var table = document.getElementById('student');
    var rowCount = table.rows.length;
    var row =  table.insertRow(rowCount);
    row.innerHTML = ' ';
    for(i=0;i<3;i++)
        {   
            var row = table.insertRow(rowCount+i+1);
            row.innerHTML = table.rows[i].innerHTML;    
            if(i==0)
            {
                row.id="st"+a1+"";
            }
        }       
    count++;
}

function addRow(data)
{
    var table = document.getElementById('student');
    var rowCount = table.rows.length;
    var row =  table.insertRow(rowCount);
    row.innerHTML = '&nbsp;';
    for(i=0;i<3;i++)
        {   
            var row = table.insertRow(rowCount+i+1);
            row.innerHTML = table.rows[i].innerHTML;    
            if(i==0)
            {
                row.id="st"+a1+"";
            }
        }       
    count++;
} 

function deleteRow(data) 
{
    var table = document.getElementById('student');
    var rowCount = table.rows.length;
        var p=data.parentNode.parentNode;
        p.parentNode.removeChild(p);
}

我的HTML代码

<fieldset>
<legend align="center">Student Information</legend> 
<br>
<table id="student">
    <tr id="s1">        
        <th><select name="" width="250px"> 
        <option value="" selected align="center">student Type</option>
        <option value="">male</option>
        <option value="">female</option>
        </select></th>
        <th><input type="button" value="+" onclick="addst(this)"/>
        <th><input type="button" value="-" onclick="delst(this)"/>
    </tr>

    <tr id="label">
        <th align="left">class info</th>
        <th align="left">Math</th>
        <th align="left">Phy</th>
        <th align="left">Chem</th>
        <th align="left">Total</th>
        <th align="left">Average</th>   
    </tr>
    <tr id="c1">
        <td>
            <select> 
                <option value="" selected>Select your class</option>
                <option>8</option>
                <option>9</option>
                <option>10</option>
                <option>11</option>
            </select>
        </td>

        <td><input type="text" id="val02" size="16" name="math" placeholder="Math marks"/></td>
        <td><input type="text" id="val03" size="16" name="phy" placeholder="Phy marks"/></td>
        <td><input type="text" id="val04" size="16" name="chem" placeholder="Chem marks"/></td>
        <td><input type="text" id="val06" size="16" name="total" placeholder="Total marks"/></td>
        <td><input type="text" id="val07" size="16" name="avg" placeholder="Average marks"/></td>
        <th><input type="button" value="+"  id="r1" onclick="addRow(this)" /></th>          
        <th><input type="button" value="-"  id="r1" onclick="delRow(this)" /></th>
    </tr>
</TABLE>
</fieldset>

'addst' 'addRow' 功能正在运行,但不知道删除功能应该如何写的。

'delst' 应删除相应的学生信息,而 'delRow' 应删除每个人行。

0 个答案:

没有答案