Html 在不执行提交的表单中添加常规按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6617212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add regular button inside form that does not perform a submit
提问by content01
I have this form declaration:
我有这个表格声明:
<form method="post" action="/web_services/buscar_vuelos?method=get">
<div id="addSegment_wrapper">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="addTr" style="display: inline;">
<span class="ui-button-text">Add Segment</span>
</button>
</div>
<input id="web_services_submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button- text-only" type="submit" value="Search" name="commit">
</form>
And, although I didn't specify "addSegment_wrapper" button as a submit one, every time I click on it, it calls the form action. I just want to treat this button as a regular one.
而且,虽然我没有指定“addSegment_wrapper”按钮作为提交按钮,但每次我点击它时,它都会调用表单操作。我只是想把这个按钮当作一个普通的按钮。
What should I do?
我该怎么办?
回答by switz
You could do
你可以做
<button type="button">Add Segment</button>
回答by Cfreak
Do this:
做这个:
<button type="button" class="(rest of your classes)">Rest of your code</button>
回答by Ole Kristian Ekseth
Closer to Occams razor (for complex schemes*) could be to construct the 'form to be submitted' separately, ie, to not (ie, drop the use of) the "form" tag: for a description of the latter, please see "how to ajax post a form that includes fields in a dynamic table for which both rows and columns can be added dynamically"
更接近奥卡姆剃刀(对于复杂的方案*)可能是单独构建“要提交的表格”,即不(即放弃使用)“表格”标签:有关后者的说明,请参阅“如何使用ajax发布包含动态表中字段的表单,可以动态添加行和列”
* eg, when your form consists of multiple interaction-events, where a subset is used for form-submission.
* 例如,当您的表单包含多个交互事件时,其中一个子集用于表单提交。