js通过行列获取表格中input的值

时间:2024-03-06 07:41:40
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>New Document</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
    <TABLE width="100%" border="1" id="tb">
        <TR>
            <TD><INPUT TYPE="text" NAME="a1" value="张三"></TD>
            <TD><font color="red"></font></TD>
            <TD>21</TD>
        </TR>
        <TR>
            <TD><INPUT TYPE="text" NAME="a2" value="李四"></TD>
            <TD><font color="red"></font></TD>
            <TD>19</TD>
        </TR>
    </TABLE>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
        getValue();
        function getValue() {
            alert("表格总行数=" + tb.rows.length);
            for (i = 0; i < tb.rows.length; i++) {
                Names = tb.rows[i].cells[0].getElementsByTagName("INPUT")[0].value;
                gender = tb.rows[i].cells[1].innerHTML;
                age = tb.rows[i].cells[2].innerText;
                alert(Names);
                alert(gender);
                alert(age);
            }
        }
    //-->
    </SCRIPT>
</BODY>
</HTML>