【问题标题】:HTML tag form without "action" attribute没有“动作”属性的 HTML 标记表单
【发布时间】:2017-12-05 10:02:20
【问题描述】:

我在一个 HTML 页面中使用这个 HTML 代码:

<form method="post">
  <div class="form-group">
    <input type="text" class="form-control" name="username">
  </div>
  <div class="form-group">
    <input type="password" class="form-control" name="password">
  </div>
  <input type="hidden" name="ref" value="post-ad.php"/>
  <button type="submit" name="submit" id="submit" class="btn">S'identifier</button>
</form>

单击提交按钮时,此表单将执行哪个操作?我注意到它在此示例中执行名为"ref" 的输入值"post-ad.php""index.php""dashboard.php"。正常吗?!据我所知,action 属性是强制性的?

【问题讨论】:

  • 如果没有action 属性,它将根据method POST/GET 到同一页面。 action 不是强制性的
  • stackoverflow.com/questions/1131781/… 如果没有 action 属性,则使用当前页面。您名为 ref 的字段就像普通输入一样,因此该值将在 $_POST['ref'] 中作为字符串提供。

标签: html


【解决方案1】:

如果没有 action 属性,它将POST/GET 到同一页面 see here

【讨论】:

    【解决方案2】:

    如果我理解正确,您是在询问 &lt;form&gt; 内部的操作属性。

    如果你什么都不放在那里,它会将 POST 发送到它现在所在的同一页面。如果该表单在“index.php”中,它会将所有&lt;form&gt; 数据发送到“index.php”

    【讨论】:

      【解决方案3】:

      您使用此代码无需操作即可调用表单:

      <form action="javascript:void(0);"></form>
      

      【讨论】:

        猜你喜欢
        • 2015-07-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-13
        • 2010-10-11
        • 2013-06-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多