Can I make a <button> not submit a form?
I've got a form, with 2 buttons
<a href="index.html"><button>Cancel changes</button></a>
<button type="submit">Submit</button>
I use jQuery UI's button on them too, simply like this
$('button').button();
However, the first button also submits the form. I would have thought that if it didn't have the type="submit"
, it wouldn't.
Obviously I could do this
$('button[type!=submit]').click(function(event) { event.stopPropagation(); });
But is there a way I can stop that back button from submitting the form without JavaScript intervention?
To be honest, I used a button only so I could style it with jQuery UI. I tried calling button()
on the link and it didn't work as expected (looked quite ugly!).
button
元素的type
属性的默认值是“submit”。
<button type=button>Submit</button>
The button
element has a default type of submit
.
You can make it do nothing by setting a type of button
:
<button type="button">Cancel changes</button>
Just use good old HTML:
<input type="button" value="Submit" />
Wrap it as the subject of a link, if you so desire:
<a href="http://somewhere.com"><input type="button" value="Submit" /></a>
Or if you decide you want javascript to provide some other functionality:
<input type="button" value="Cancel" onclick="javascript: someFunctionThatCouldIncludeRedirect();"/>
链接地址: http://www.djcxy.com/p/6226.html
上一篇: 如何使用可点击标签创建HTML复选框
下一篇: 我可以使<按钮>不提交表单吗?