javascript - 未捕获的类型错误 : Cannot read property 'element' of undefined when submitting form

标签 javascript html

我有一个使用 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/

相关文章:

javascript - 动态添加&lt;meta/>标签

javascript - 为什么 Reflux.js ListenAndPromise 帮助程序不起作用?

javascript - 我的 JavaScript 代码为 getElementById 返回 null

javascript - 如何找到 Canvas 创建的文本的中心位置坐标?

javascript - 在浏览器中打开 index.html 时,jQuery 代码不会运行。控制台没有错误

javascript - Jquery onChange div 内容

javascript - 如何在 express 中导出应用程序对象?

javascript - 合并 $.get 和 $.ready

javascript - 如何在参数中提供默认值?

php - 更新同一个ID的三张图片的逻辑是什么?