简体   繁体   English

为什么是 <input type=“button”> 提交表格?

[英]Why is <input type=“button”> submitting a form?

<form name="callEventForm" method="post" action="/PDC/callevent.do">

     ...

     <input type="button" value="Save" name="addCallEvent" id="addCallEvent" onclick="alert('You clicked me!')"/>

     ...

 </form>

When clicking this "Save" button, the form is submitted instead of displaying the alert. 单击此“保存”按钮时,将提交表单而不是显示警报。 I was lead to believe that type="button" would cause the form to not submit on click. 我一直认为type =“button”会导致表单在点击时不提交。

Change: 更改:

onclick="alert('You clicked me!')"

To: 至:

onclick="alert('You clicked me!');return false;"

I hate to answer my own questions but this was a weird one. 我讨厌回答我自己的问题,但这很奇怪。 There was an ajax:updateField tag that was overriding the onclick event of the button. 有一个ajax:updateField标记覆盖了按钮的onclick事件。 Changing the source event of the ajax:updateField allowed my established onclick event to fire appropriately. 更改ajax的源事件:updateField允许我已建立的onclick事件适当地触发。 I know that there's no way anyone would have caught that based on the code I posted, but the rest of the page is so much code that I would hate to make people wade through it. 我知道根据我发布的代码,任何人都无法捕获它,但页面的其余部分是如此多的代码,我讨厌让人们趟过它。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM