Button Onclick does not work inside form

痴心易碎 提交于 2019-12-20 03:30:08

问题


Good Day

I am using an ASP.NET webform where I have wrapped the following button inside the form tags:

<form runat="server">

  <button class="btn btn-primary" onclick="window.location='http://google.co.za';">Login</button>

</form>

ISSUE: The problem is that when clicking on the button, it just directs to the current page...does not redirect. However, when I remove the form tags, the button works. If I leave the form tags and I use an anchor tag to relocate, it works as well...It is just the button that is giving me issues.

Why is that?

I am using Twitter bootstrap as well(extra info..)

Thank you


回答1:


Add type="button" attribute to your button tag. Without it button works as submit.



来源:https://stackoverflow.com/questions/15522521/button-onclick-does-not-work-inside-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!