[英]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=submit
和type=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>
,因此有不同的方法可以实现您的目标。
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>
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 事件或收听点击事件,您可以做同样的事情和更多的事情(这里没有演示,如果您不知道我在说什么,请在此处阅读一些相关信息
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
我推荐
ID
或CLASS
而不是TYPE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.