输入类型为“submit”的元素周围的href是什么意思?

14

为什么在IE中,在input type submit周围放置a href不起作用?(我应该怎么做才能解决它)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org    /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen">
</head>
<body>
<a href="1.html"><input type="submit" class="button_active" value="1"></a>
<a href="2.html"><input type="submit" class="button" value="2"></a>
<a href="3.html"><input type="submit" class="button" value="3"></a>
</body>
</html>

style.css:

* {
    margin: 0;
    padding: 0;
}

/* CSS Buttons: http://www.web4site.de/css/css-buttons.php */
.button {
    padding:0;
    margin:0;
    border:none;
    font-size:14px;
    background: url(../img/button.gif) no-repeat center;
    color: #000000;
    height:27px;
    width:134px; 
    font-variant:small-caps;
}

.button:hover {
    padding:0;
    margin:0;
    border:none;
    font-size:14px;
    background: url(../img/button.gif) no-repeat center;
    color: #FF0000;
    height:27px;
    width:134px; 
    text-decoration:none;
    font-variant:small-caps;
}

.button_active {
    padding:0;
    margin:0;
    border:none;
    font-size:14px;
    background: url(../img/button.gif) no-repeat center;
    color: #FF0000;
    height:27px;
    width:134px; 
    font-variant:small-caps;
}

这在火狐浏览器中很好用...


你必须接受HTML有其局限性。 - Sotiris
6个回答

23
为什么要在锚点内放置提交按钮?你要么是想提交表单,要么是要跳转到不同的页面。究竟是哪一个呢?
要么提交表单:
<input type="submit" class="button_active" value="1" />

或者前往另一页:

<input type="button" class="button_active" onclick="location.href='1.html';" />

<input type="button" class="button_active" onclick="location.href='1.html';" /> 这个可以正常工作。非常感谢 :) - Marc
请使用链接来链接到网页。 - MatTheCat
@Kon 如果你想做类似这样的事情,<a href="?cmd=save">保存</a> 但同时也要重定向到另一个页面怎么办? - Yunfei Chen

12

因为它没有任何意义(HTML 5明确禁止此类操作),所以它无法正常工作。

要解决此问题,请确定您需要链接还是提交按钮,并仅使用实际需要的那种类型(提示:由于您没有表单,因此提交按钮毫无意义)。


这对我来说很有意义,因为我需要一个链接,并使用输入类型对其进行格式化(包括背景图像等)。 - Marc
1
当您单击链接时,您将跟随该链接。当您单击提交按钮时,您会提交一个表格。当您单击链接内的提交按钮时,您同时跟随链接并提交表单?这两者都会将浏览器发送到新的URI?这根本没有任何意义。 - Quentin
2
那是你的问题。提交按钮是用于提交表单的东西,而不是用于使某物看起来像按钮的东西。如果你想让某物看起来像按钮,请使用 CSS。 - Quentin
我正在使用CSS来格式化按钮 :) 我不需要该按钮用于提交表单(因此没有表单标签)。 - Marc
2
格式化锚点,去掉按钮。 - Quentin
@marc,使用span元素代替input - Maksim Vi.

2
<a href="1.html"><input type="text" class="button_active" value="1"></a>
<a href="2.html"><input type="text" class="button" value="2"></a>
<a href="3.html"><input type="text" class="button" value="3"></a>

尝试一下。除非你确实需要坚持使用“submit”类型,否则我提供的内容应该可行。如果你会坚持使用“submit”,那么上面提到的一切都是正确的,这是毫无意义的。

1
将链接位置放置在包裹的
标记的 action="" 中。
你的第一个链接将是:
<form action="1.html">
    <input type="submit" class="button_active" value="1">
</form>

输入类型的链接并不相同。 - Marc
我假设他想要提交输入数据,因此需要三个不同的表单。 - Phil

0

我同意Quentin的观点。你为什么要这样做没有道理。这是语义Web概念的一部分。您必须规划网站对象以进行未来的集成/扩展。如果不遵循正确的用例,其他Web应用程序或网站无法与您的内容交互。

IE和Firefox是两个不同的浏览器。有很多IE允许的事情,但Firefox和其他符合标准的浏览器会拒绝。

如果您想创建没有实际提交数据的按钮,则使用DIV/CSS的组合。


0
你可以做到。输入类型submit应该在表单内部。然后,你所要做的就是在表单标签内的action属性中编写要重定向到的链接。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接