gpt4 book ai didi

javascript - 从 JavaScript 提交的表单不起作用

转载 作者:数据小太阳 更新时间:2023-10-29 03:53:26 24 4
gpt4 key购买 nike

我在要使用 JavaScript 提交的页面上有一个表单:

<script>
function deleteFromlist(listname, listvalue)
{
if (confirm("Are you sure you want to delete this?")) {
document.getElementById('fromList').value=listname;
document.getElementById('deleteRecord').value=listvalue;
document.getElementById('watchlistForm').submit(); // Fails here
}
}
</script>

<form method='POST'
id='watchlistForm'
enctype='multipart/form-data'
action='process.php'>

<input type='text' name='fromList' id='fromList' value=''>
<input type='text' name='deleteRecord' id='deleteRecord' value=''>
<input type='submit' name='submit' value='submit'>
</form>

JavaScript 函数是从页面其他地方的表格中的 href 调用的。它正确填充了输入字段,但失败并显示此消息:

TypeError: document.getElementById(...).submit is not a function
document.getElementById('watchlistForm').submit();

如果我替换文档....submit();与

alert(document.getElementById('watchlistForm').innerHTML

然后我在警告框中得到了预期的输出。因此

document.getElementById('watchlistForm')

确实解析为表单元素。

在表单上添加提交按钮按预期工作。

为什么这不起作用,我该如何解决?

最佳答案

呃,似乎名为“提交”的按钮屏蔽了该方法。改变:

 input type='submit' name='submit' value='submit'

 input type='submit' name='submitButton' value='submit'

解决了问题。

关于javascript - 从 JavaScript 提交的表单不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39149474/

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