2

为什么这些未定义?它们包含在表单验证 js 文件中:

var student_name = document.reg_page.student_name.value; var course_id = document.reg_page.course_id.value;

当我有这个表格

<div id="container">
<div id="page">
    <form name="reg_page" action="thanks.htm" onsubmit = "return form_validation()" method="post">
    <table id="form">
        <tr>
            <td colspan="2"><div id="table_title">Web Registration Form</td>
        </tr>
        <tr>
            <td class="label">Student Name:</td><td><input name="student_name" id="s" size="15" value="name"/></td>
        </tr>
        <tr>
            <td class="label">Course ID:</td><td><input name="course_id" id="c" size="10" /></td>
        </tr>
        <tr>
            <td class="label">Select the programming languages you have studied:</td>
            <td>
                <div><input type="checkbox" name="js" id="y" value="JS" />JavaScript</div>
                <div><input type="checkbox" name="py" id="y" value="Python" />Python</div>
                <div><input type="checkbox" name="asp" id="y" value="ASP.NET" />ASP.NET</div>
                <div><input type="checkbox" name="php" id="y" value="PHP" />PHP</div>
            </td>
        </tr>
        <tr>
            <td class="label">Expected Year of Graduation:</td>
            <td>
                <div><input type="radio" name="year" id="y" value="2011" />2011</div>
                <div><input type="radio" name="year" id="y" value="2012" />2012</div>
                <div><input type="radio" name="year" id="y" value="2013" />2013</div>
                <div><input type="radio" name="year" id="y" value="2014" />2014</div>
            </td>
        </tr>
        <tr>
            <td colspan="2" id="buttons">
                <input type="submit" name="sub" value="Log In" id="s" /> <input type="reset" name="re" value="Clear Form" id="r" />
            </td>
        </tr>
    </table>
    </form>
</div>
4

1 回答 1

0

您是否在页面的其余部分加载之前做出这些声明?

例如,如果您在正文上方包含脚本并且声明不在函数中,它将查找浏览器尚未创建的表单和输入元素。

于 2012-10-19T20:43:29.243 回答