[英]Click a submit type input when a button is clicked
How to click an input with the type submit when a button was clicked? 单击按钮时如何单击类型为提交的输入?
$(document).on('click', 'button.editManufacturer', function(event) {
event.preventDefault();
$(".editManufacturerSubmit").click();
});
The snippet above is the code i have so far, but it doesn't work? 上面的代码段是我到目前为止的代码,但这行不通吗?
Thank you! 谢谢!
===== EDIT ===== =====编辑=====
Let me explain my problem a little bit more exactly! 让我更确切地解释我的问题!
I've a lot of forms that i want to submit via only one button. 我想通过一个按钮提交许多表格。
The following things I have tried before: 我之前尝试过的以下事情:
$("button.editManufacturer").click( function() {
$('form.editManufacturer').submit();
});
========================================================================= ================================================== =======================
"form" attribute at the button / input 按钮/输入处的“表单”属性
========================================================================= ================================================== =======================
and some other things, were i havent the snippets anymore 还有其他一些事情,我是否没有这些片段
========================================================================= ================================================== =======================
NOTE: only the last form is getting submitted 注意:仅提交最后一张表格
You can Try this 你可以试试看
$('button.editManufacturer').on('click', function(event) {
$(".editManufacturerSubmit").trigger("click");
});
I am Hopeful it will work for you. 我希望它将为您服务。
Your code seems to work as it is, you may have to provide more code which replicates the problem. 您的代码似乎可以正常工作,您可能必须提供更多代码来复制问题。
$(document).on('click', 'button.editManufacturer', function(event) { event.preventDefault(); $(".editManufacturerSubmit").click(); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form action="https://httpbin.org/post" method="post"> <button class="editManufacturer" >button</button> <input type="submit" class="editManufacturerSubmit" value="get" onClick="alert('hi')"/> </form>
Try this 尝试这个
$(document).ready(function() {
$("form").submit(function(event) {
event.preventDefault();
});
}); });
I think what you need is this 我想你需要的是
$('.editManufacturer').click(function(){
$('form').submit();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.