我有一个使用 PHP 的 HTML div 输出,当单击“提交”时,它应该提交表单并触发 JS 函数。提交后,Chrome 中的 JS 控制台出现以下错误:
未捕获的类型错误:无法读取未定义的属性“元素”
我的 HTML(包装在 PHP heredoc 中)
<div id="tab5" class="tab">
<div id="reopen_case_form">
This Case has been previously closed by Workbooks Support. You can re-open this ticket at any time by providing a reason why you'd like to do so and clicking "Re-open Case".
<table class="update_case">
<tr><td style="padding: 10px">Summary:<input id="name" name="name" type="text" size="80" maxlength="255" class="required"/></td></tr>
<tr><td><textarea id="description" name="description" cols="255" rows="50"></textarea></td></tr>
<tr>
<td colspan="2" style="padding-top: 10px;">
<input type="file" class="file" name="file1" id="file1" style="display: inline">
<input type="file" class="file" name="file2" id="file2" style="display: inline">
<input type="file" class="file" name="file3" id="file3" style="display: inline">
</td></tr>
</table>
<p><button type="submit" onclick="on_reopen_case()" style="float:left; margin-top: 10px; margin-bottom: 10px;" value="reopen_case" id="reopen_case" name="reopen_case" class="quietbutton">Re-open Case</button></p>
</div>
</div>
我的Javascript:
<script type="text/javascript">
function on_reopen_case() {
if (!$("#reopen_case_form").valid()){ return false; }
$('#reopen_case').attr('disabled', 'disabled');
$('#reopen_case').text('Re-opening case. Please wait...');
document.body.style.cursor = "progress";
$("#function").val("reopen_case");
fade();
$("#reopen_case_form").submit();
};
</script>
表单似乎已提交,但未将按钮文本更改为“重新打开案例”,也未将#function 设置为指定值。
令人恼火的是,我在其他地方也使用过类似的方法,但效果不错:
<div id="tab3" class="tab">
<div id="update_case_form">
Provide a summary and detailed description of your update below, including screenshots where applicable. Click "Update Case" to submit your update to the Workbooks Support team.
<table class="update_case">
<tr><td style="padding: 10px">Summary:<input id="name" name="name" type="text" size="80" maxlength="255" class="required"/></td></tr>
<tr><td><textarea id="description" name="description" cols="255" rows="50"></textarea></td></tr>
<tr>
<td colspan="2" style="padding-top: 10px;">
<input type="file" class="file" name="file1" id="file1" style="display: inline">
<input type="file" class="file" name="file2" id="file2" style="display: inline">
<input type="file" class="file" name="file3" id="file3" style="display: inline">
</td></tr>
</table>
<p><button type="submit" onclick="on_create_activity()" style="float:left; margin-top: 10px; margin-bottom: 10px;" value="create_activity" id="create_activity" name="create_activity" class="quietbutton">Update Case</button></p>
</div>
</div>
Javascript
<script type="text/javascript">
function on_create_activity() {
if (!$("#update_case_form").valid()){ return false; }
$('#create_activity').attr('disabled', 'disabled');
$('#create_activity').text('Updating case. Please wait...');
document.body.style.cursor = "progress";
$("#function").val("create_activity");
fade();
$("#update_case_form").submit();
};
</script>
我这辈子都弄不明白哪里出了问题!帮助....
最佳答案
我认为我可能已经想通了...我使用的是显然不允许的嵌套表单... Cannot Read Property 'Elements' of Undefined - in JS Console
感谢大家的建议:)
关于javascript - 未捕获的类型错误 : Cannot read property 'element' of undefined when submitting form,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34372892/