且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

<input type='submit'/> 的区别和 <button type='submit'>text</button>

更新时间:2022-11-30 11:53:04

不确定你的传说来自哪里,但是:

Not sure where you get your legends from but:

与:

<button type="submit">(html content)</button>

IE6 将提交标签之间此按钮的所有文本,其他浏览器只会提交值.使用 可以让您在按钮设计上有更多的布局***.就其所有意图和目的而言,一开始它似乎非常出色,但各种浏览器怪癖有时使其难以使用.

IE6 will submit all text for this button between the tags, other browsers will only submit the value. Using <button> gives you more layout freedom over the design of the button. In all its intents and purposes, it seemed excellent at first, but various browser quirks make it hard to use at times.

在您的示例中,IE6 会将 text 发送到服务器,而大多数其他浏览器不会发送任何内容.要使其跨浏览器兼容,请使用 .更好的是:不要使用该值,因为如果您添加 HTML,那么在服务器端接收到的内容就会变得相当棘手.相反,如果您必须发送额外的值,请使用隐藏字段.

In your example, IE6 will send text to the server, while most other browsers will send nothing. To make it cross-browser compatible, use <button type="submit" value="text">text</button>. Better yet: don't use the value, because if you add HTML it becomes rather tricky what is received on server side. Instead, if you must send an extra value, use a hidden field.

与:

<input type="button" />

默认情况下,这几乎没有任何作用.它甚至不会提交您的表单.您只能在按钮上放置文本并通过 CSS 为其指定大小和边框.它最初(和当前)的意图是执行脚本而无需将表单提交给服务器.

By default, this does next to nothing. It will not even submit your form. You can only place text on the button and give it a size and a border by means of CSS. Its original (and current) intent was to execute a script without the need to submit the form to the server.

与:

<input type="submit" />

像前者,但实际上提交了周围的表单.

Like the former, but actually submits the surrounding form.

与:

<input type="image" />

与前者(提交)一样,它也会提交表单,但您可以使用任何图像.当需要提交表单时,这曾经是使用图像作为按钮的首选方式.为了获得更多控制,现在使用 .这也可以用于服务器端图像映射,但现在这种情况很少见.当您使用 usemap 属性和(有或没有该属性)时,浏览器会将鼠标指针 X/Y 坐标发送到服务器(更准确地说,按钮内的鼠标指针位置单击它的那一刻).如果你只是忽略这些额外的东西,那不过是一个伪装成图片的提交按钮.

Like the former (submit), it will also submit a form, but you can use any image. This used to be the preferred way to use images as buttons when a form needed submitting. For more control, <button> is now used. This can also be used for server side image maps but that's a rarity these days. When you use the usemap-attribute and (with or without that attribute), the browser will send the mouse-pointer X/Y coordinates to the server (more precisely, the mouse-pointer location inside the button of the moment you click it). If you just ignore these extras, it is nothing more than a submit button disguised as an image.

浏览器之间存在一些细微的差异,但除上述 标记外,所有浏览器都会提交 value-attribute.

There are some subtle differences between browsers, but all will submit the value-attribute, except for the <button> tag as explained above.