gpt4 book ai didi

javascript - document.reg_page 未定义

转载 作者:行者123 更新时间:2023-11-30 06:38:40 24 4
gpt4 key购买 nike

为什么这些是未定义的?它们包含在表单验证 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>

最佳答案

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

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

关于javascript - document.reg_page 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12982097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com