jquery - $( "#target").submit();不工作

标签 jquery html forms

出于某种原因,我不明白为什么我的表单没有使用 $( "#target" ).submit(); 提交.

<html>
<head>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/2.2.3/jquery.min.js'></script>    
<script>
function saveItem()
{
    console.log($("#frm"));
    $("#frm").submit();
}
</script>
</head>
<body>
<form id="frm" action="form.php" method="post">
    <a href="javascript:;" title="Save" onclick="saveItem()">save</a>
    <button type="submit" id="submit">Save</button>        
</form>
</body>
</html>

最佳答案

表单元素中的 id 属性无法submit,请尝试使用其他名称。

why we shouldn't set id as submit

因为如果表单控件(例如提交按钮)的名称或 ID 为 Submit,它将屏蔽表单的提交方法。

关于jquery - $( "#target").submit();不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40974257/

相关文章:

jQuery 循环输入问题

javascript - 如何根据元素的 ID 在 console.log 中打印值?

html - 使用 CSS 不能做什么

html - 一个div,相互独立,在整个body的中间偏左,高度变为

html - 进度指示器从进度条外开始

Javascript:表单验证 - 从更正的字段中删除错误消息

javascript - CSS:如何使输入框中的下拉菜单不与长文本重叠?

javascript - 无法从 jQuery 的 $.each 返回结果数组

html - 如何编写用于离线完成的 HTML 表单

jquery - 在填充主字段之前禁用字段