将按钮放在html表单中有什么好处?

时间:2014-10-13 11:26:25

标签: html

在html表单中放置一个按钮与直接在正文中使用它有什么好处吗?

<form id="viewForm" method="post">
  <input id="editBtn" type="button" value="Edit" />
</form>

1 个答案:

答案 0 :(得分:0)

将其放入表单的主要优点是您可以使用

   <form name="input" action="demo_form_action.asp" method="get">

按钮将与动作一起使用。喜欢

例如发送按钮

  <form name="input" action="demo_form_action.asp" method="get">
      Username: <input type="text" name="user">
      <input type="submit" value="Submit">
  </form> 

没有表单的按钮可用于调用函数,例如

  <button onlick="function();"></button>

但你可以使用onclick事件处理程序来获得相同的链接 所以当一个按钮与形式(大多数时候)一起使用时,它才有意义

您可以使用搜索按钮和事件处理程序的更多示例

相关问题