为什么<a href=""> tag doesn&#39;t work inside a form

时间:2016-06-30 08:17:25

标签: html

why a href tag in html does not work inside a form? I am trying to use that for my jsp page transitions, but it really doesn't work.

here's my code:

<form method="GET" action="Controller">
      <input type="submit" value="Search"/>
      <a href="/Controller?action=add"><input 
         type="button" value="Add"/></a>
</form>

what is the problem why it's not working?

1 个答案:

答案 0 :(得分:0)

您无法在按钮中包含锚点,因为它们在点击时都会执行某些操作 - 它也不是有效的HTML。尝试:

<form method="GET" action="/Controller?action=add">
      <input type="submit" value="Search"/>
      <input type="button" value="Add"/>
</form>

查看是否有效,但不要在锚点中包含按钮:)

此外,请参阅此问题,了解其他不能包含在代码Can I nest a <button> element inside an <a> using HTML5?

中的元素