Home  >  Article  >  Web Front-end  >  HTML 为同一表单设置不同的action_html/css_WEB-ITnose

HTML 为同一表单设置不同的action_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:25:311333browse

对一张表单,希望通过不同的按钮,将表单值转向不同的页面,然而form中的action值只有一个,不采取某种特殊的方式是肯定不能简单实现的,如下所示:

通过将form中的action值设为空,并取nama="form1",然后在表单中的button或者submit中加入onclick="form1.action='1.php';form1.submit();",可以明显看出再这里重新设置了form的action值,并通过form1.submit();进行了跳转,form1为为form取的name,这样通过上述代码中的不同button则可分别将表单值传给不同的页面

注意该方法不能再跳转页面中加入参数,只能是纯页面,也即转向1.php?action=action1是不可以的,若除了想传递text域或其他的内容,需使用,在value中加入所想传递的值

通过如上方法可以使:

  1. 同一个表单数据可通过不同按钮传递给不同页面
  2. 不同按钮可以处理同一个text域
  3. 通过hidden域,也可将不同的表单数据传递给不同页面
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn