简体   繁体   English

HTML | 我可以在一个按钮中分配 type=button 和 type=submit 吗?

[英]HTML | Can I assign type=button and type=submit in one button?

I would like to assign type=submit and type=button in one button like我想在一个按钮中分配type=submittype=button

<button type="button" type="submit></button>

I need to use the type=submit so that I can put all the answers in my database and type=button to bring them to another modal.我需要使用type=submit以便我可以将所有答案放在我的数据库中,然后type=button将它们带到另一个模式。 That's why I'd like to use both types in one button.这就是为什么我想在一个按钮中使用这两种类型。 I hope you can help me or teach some alternatives.我希望你能帮助我或教一些替代方案。 Thank you谢谢

<form class="mt-1" method="POST">
   <div class="form-group d-flex justify-content-center">
   <input type="text" class="form-control w-100" placeholder="First Name" name="firstName">
   </div>
<button type="submit" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#confirmModal" >Next</button>
</form>
<div class="modal fade" id="confirmModal" >
    <div class="modal-dialog">
        <div class="modal-content">
            
                <div class="modal-body">
                    <p>Your form has been submitted</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary "  data-bs-dismiss="modal">Confirm</button>
                </div>
            
        </div>
    </div>
</div>

You cant add more than one type on a button, usually when you try and do a submit its better to do a 'type="submit"' on the form itself, if the button is inside the form it usually recognizes it and tells the form to submit, hope that helps.您不能在按钮上添加多个类型,通常当您尝试提交时,最好在表单本身上执行“type="submit"”,如果按钮在表单内,它通常会识别它并告诉表单提交,希望对您有所帮助。

You can't use 2 different types.您不能使用 2 种不同的类型。 But you can just use type="button" .但是你可以只使用type="button" Regular buttons dont fire forms only if they got type="submit" otherwise they just perform a click action that is not bound to anything.常规按钮只有在获得type="submit"时才会触发 forms ,否则它们只会执行未绑定到任何内容的单击操作。 So since you have a <button type="button"...>Confirm</button> there are different ways to achive your goal.因此,由于您有一个<button type="button"...>Confirm</button> ,因此有不同的方法可以实现您的目标。

  1. Propably the simplest way, add a onClick submit event可能是最简单的方法,添加一个 onClick 提交事件

    <button type="button" class="btn btn-primary" data-bs-dismiss="modal" onClick="submit()" <==== >Confirm</button>
  2. You can do the same thing and more stuff if you add a js file, get the button and bind a onClick event or listen to the click event (no demo here, if you not know what im talking about, read some about it here如果您添加 js 文件、获取按钮并绑定 onClick 事件或收听点击事件,您可以做同样的事情和更多的事情(这里没有演示,如果您不知道我在说什么,请在此处阅读一些相关信息

  3. You can give the button a type="submit" and change the way how modal seeks for the button.您可以给按钮一个type="submit"并更改模态搜索按钮的方式。 I recommend ID or CLASS instead of TYPE我推荐IDCLASS而不是TYPE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我不能单击此按钮? (输入类型提交) - Why Can't I click this button? (Input type submit) 我可以使用提交表单值吗? <input type=“button” /> ? - Can I submit form values using <input type=“button” />? 如果按钮类型未提交,我如何检查我的按钮是否在 php 中被按下? - How can i check if my button is pressed or not in php if button type is not submit? Symfony2:我怎么做一个<button type=“submit”>或只是</button> - Symfony2: how can I make a <button type=“submit”> or just <button> 如何在CSS中使type =“ submit”看起来像type =“ button” - How can I make a type=“submit” look in css like a type=“button” 输入类型提交与输入类型按钮 - input type submit vs input type button 提交表单<button type=“submit”>至同一页面</button> - submit form with <button type=“submit”> to the same page 我创建了一个html提交按钮,并与php代码连接,但是,选择之后,我该如何返回我的html页面? - I have created one html submit button and connects with php code but, after selecting that how can i go back my html page? 使用button type =“submit”而不是input - laravel - using button type=“submit” instead of input - laravel 按钮类型提交在IE6.0中不起作用 - Button type submit not working in IE6.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM