为什么jQuery“切换”?按钮触发表单上的“提交”按钮?
我构建了一个相当复杂的表单,其中包含一个隐藏部分,用户可以切换打开该部分以便在必要时输入更多信息。但是,当您点击标有我有更多本地性的此切换按钮时,它会触发提交按钮并过早提交表单。
I have built a fairly complex form which includes a hidden section that the user can toggle open for entering more information if necessary. However, when you click on this toggle button labeled I have more Nativities, it triggers the submit button and prematurely submits the form.
表单现在是开发人员,但可以在这里找到它。
The form is in dev right now, but it can be found here.
我用于切换按钮的代码是:
The code I am using for the toggle button is:
<script type="text/javascript">
$(function() {
$("#schedule").accordion({ header: "h5", collapsible: true });
$("#more-nativities").hide();
$("#toggle").click(function() {
$("#more-nativities").slideToggle("slow");
});
});
</script>
提交按钮的代码非常基本:
The code for the submit button is pretty basic:
<input id="submit2" type="image" src="_images/btn_register.jpg" name="submit" alt="" onmouseover="javascript:this.src='_images/btn_register2.jpg'" onmouseout="javascript:this.src='_images/btn_register.jpg'"/>
切换按钮的代码是:
<button id="toggle">I have more nativities</button>
关于为什么切换按钮触发提交的任何想法?更重要的是如何解决问题?
Any ideas as to why the toggle button is triggering the submit? And more importantly how to solve the problem?
谢谢!
尝试添加类型,即:
<button type="button" id="#toggle">Text</button>
http://www.w3schools.com/tags/tag_button.asp 说应该始终定义。浏览器可能默认为提交按钮。
http://www.w3schools.com/tags/tag_button.asp says this should be always defined. It's possible the browser is defaulting to a submit button.