按钮 Onclick 在表单内不起作用 [英] Button Onclick does not work inside form
问题描述
美好的一天
我正在使用一个 ASP.NET 网络表单,我在表单标签中包含了以下按钮:
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.
这是为什么呢?
我也在使用 Twitter 引导程序(额外信息..)
I am using Twitter bootstrap as well(extra info..)
谢谢
推荐答案
将 type="button"
属性添加到您的 button
标记中.如果没有它,按钮将作为 submit
.
Add type="button"
attribute to your button
tag. Without it button works as submit
.
这篇关于按钮 Onclick 在表单内不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!