带有 action="" 的表单 [英] Forms with action=""

查看:28
本文介绍了带有 action="" 的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现(艰难的方式),当您有一个带有 action="" 的 HTML 表单时,Webkit 浏览器会以与 Firefox 和 Internet Explorer 不同的方式处理它.

I just found out (the hard way), that when you have a HTML form with action="", Webkit browsers treat it differently to Firefox and Internet Explorer.

在 FF 和 IE 中,这两个表单标签是等价的:

In FF and IE, these two form tags are equivalent:

<form method="post" action="">

<form method="post">

他们都会将表单提交回同一页面.然而,Safari 和 Chrome 会将第一个表单发送到默认页面(index.php 或其他页面)——第二个表单与 FF/IE 的工作方式相同.

They will both submit the form back to the same page. Safari and Chrome however will send that first form to the default page (index.php, or whatever) - the second form works the same as FF/IE.

我很快修改了我的代码,以便在通常会打印空操作的任何地方,它根本不添加操作属性.

I've quickly hacked my code so that anywhere where it would normally print an empty action, it doesn't add an action attribute at all.

这看起来很乱,而且不是最好的做事方式.任何人都可以提出更好的方法吗?另外,谁能告诉我为什么 Webkit 会做这样的事情?

This seems very messy and not the best way to be doing things. Can anyone suggest a better method? Also, can anyone enlighten me about why Webkit would do such a thing?

推荐答案

我通常使用

<form method='POST' action='?'>

这意味着当前的 URL,但没有参数.

This means the current URL but with no parameters.

这篇关于带有 action="" 的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆