简体   繁体   English

单击按钮时,单击提交类型输入

[英]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.

相关问题 单击时如何使按钮(输入类型=“提交”)消失 - how to make a button(input type=“submit”) dissapeared when clicked Formik 触发错误并触及非提交类型的按钮点击。 我们如何仅在单击(type =“submit”)按钮时触发 - Formik triggering errors and touched on non submit type button click. How can we only trigger when (type="submit") button clicked 单击提交输入类型时 jQuery 没有响应 - jQuery not responding when Submit input type is clicked Javascript对输入更改进行验证,仅在单击“提交”按钮时提交 - Javascript Validate on input change, only submit when Submit button clicked 使用jQuery单击父级时触发提交按钮的单击 - Trigger Click of Submit Button When Parent Is Clicked with jQuery 单击输入提交按钮时如何添加fancybox? - how to add fancybox when an input submit button is clicked? 单击提交按钮时隐藏隐藏的输入值(php / jquery) - hide a hidden input value when a submit button is clicked (php/jquery) 为什么我不能单击此按钮? (输入类型提交) - Why Can't I click this button? (Input type submit) 如何在不提交整个表单的情况下单击输入类型“提交”按钮 - How to click on an input type“submit” button without submiting the whole form 单击提交按钮时无功能 - No function when submit button is clicked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM