javascript - 提交不是js中的函数

标签 javascript html internet-explorer firefox struts2

我有一个 struts 2 表单标签,我正在尝试使用 java 脚本函数提交表单。但是当我尝试这样做时,出现以下错误。

"document.testForm.submit is not a function" IE 8(Object doesn't support this property or method)

这是我的 java 脚本函数和 html 代码:-

<script type="text/javascript">
        function testFunction()
        {
          document.testForm.action = "testAction";
           document.testForm.submit();

        }
</script>

<s:form method="POST"  id="fileForm" name="testForm"
    enctype="multipart/form-data">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
       <tbody>
        <tr>
           <td>
             <input type="button" name="submit" value="Upload File"    onclick="testFunction();"/>
           </td>
            </tr>
       </tbody>
   </table>
</s:form>

我正在使用 FF 7 和 IE 8

请帮帮我。

最佳答案

问题是您将提交按钮命名为“提交”:

<input type="button" name="submit" ...>
<!--                 ^^^^^^^^^^^^^  -->

将其更改为几乎任何其他内容。表单元素使用它们的名称作为属性添加到表单对象,以便隐藏(覆盖)表单的内置 submit 属性(这是您正在寻找的功能)。

关于javascript - 提交不是js中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7684271/

相关文章:

html - 选择选项的 IE 样式问题同时具有 selected 和 disabled 属性

javascript - 在 sinon.js 中使用 ES 模块时如何 stub 常量函数?

javascript - Telerik RadGrid 滚动条正在偏移列

javascript - 使用ajax请求下载图像

php - Magento 2 - 在成功页面上获取订单预览

javascript - 使用 setInterval 时如何停止等待光标

javascript - 在 IEAutomation 中单击按钮时如何让 Javascript 执行?

javascript - 如何在客户端浏览器中读取服务器文件

javascript - 使用JavaScript播放/暂停MP3问题

html - IE中的两个垂直滚动条