gpt4 book ai didi

javascript - 提交不是js中的函数

转载 作者:搜寻专家 更新时间:2023-10-31 21:53:35 24 4
gpt4 key购买 nike

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

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