gpt4 book ai didi

jQuery:表单未使用 $ ("#id").submit() 提交,但会使用 'submit' 按钮提交?

转载 作者:行者123 更新时间:2023-12-03 21:28:42 30 4
gpt4 key购买 nike

<form method="post" action="load_statements.php?action=load" id="loadForm"
enctype="multipart/form-data">

这是我的形式,对我来说看起来不错。在这种形式中,我放置了这个按钮:

<input type="button" name="submit" id="submit" value="Submit" onclick="confirmSubmit()" class="smallGreenButton" />

这是它调用的函数:

function confirmSubmit() {
// get the number of statements that are matched
$.post(
"load_statements.php?action=checkForReplace",
{
statementType : $("#statementType").val(),
year : $("#year").val()
},
function(data) {
if(data['alreadyExists']) {
if( confirm("Statements already exist for " + $("#statementType").html() + " " + $("#year").val() +
". Are you sure you want to load more statements with these settings? (Note: All duplicate files will be replaced)"
)) {
$("#loadForm").submit();
}
} else {
$("#loadForm").submit();
}
}, "json"
);
}

正如您所看到的,它调用了$("#loadForm").submit();,但是表单没有提交(即页面没有刷新)。这是为什么?

谢谢!

最佳答案

将按钮的“提交”名称更改为其他名称。这导致了问题。请参阅 dennisjq 的回答: http://forum.jquery.com/topic/submiting-a-form-programmatically-not-working

See the jQuery submit() documentation:

Forms and their child elements should not use input names or ids that conflict with properties of a form, such as submit, length, or method. Name conflicts can cause confusing failures. For a complete list of rules and to check your markup for these problems, see DOMLint.

关于jQuery:表单未使用 $ ("#id").submit() 提交,但会使用 'submit' 按钮提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3303874/

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