Html href 围绕输入类型提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6693566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:33:44  来源:igfitidea点击:

href around input type submit

htmlcssformsbutton

提问by Marc

why isn't a href around an input type submit not working in IE? (and what can I do to fix it)

为什么围绕输入类型提交的 href 不在 IE 中工作?(我能做些什么来解决它)

<!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:

样式.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;
}

This works fine in firefox ...

这在 Firefox 中工作正常......

回答by Kon

Why would you want to put a submit button inside an anchor? You are either trying to submit a form or go to a different page. Which one is it?

为什么要在锚点内放置一个提交按钮?您正在尝试提交表单或转到其他页面。哪一个?

Either submit the form:

要么提交表格:

<input type="submit" class="button_active" value="1" />

Or go to another page:

或者转到另一个页面:

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

回答by Quentin

It doesn't work because it doesn't make sense (so little sense that HTML 5 explicitly forbids it).

它不起作用,因为它没有意义(HTML 5 明确禁止它没有意义)。

To fix it, decide if you want a link or a submit button and use whichever one you actually want (Hint: You don't have a form, so a submit button is nonsense).

要解决此问题,请决定您想要链接还是提交按钮,然后使用您真正想要的任何一个(提示:您没有表单,因此提交按钮是无稽之谈)。

回答by Phil

Place the link location in the action=""of a wrapping formtag.

将链接位置放在action=""包装form标签的 中。

Your first link would be:

您的第一个链接是:

<form action="1.html">
    <input type="submit" class="button_active" value="1">
</form>

回答by fergatron

I agree with Quentin. It doesn't make sense as to why you want to do it like that. It's part of the Semantic Webconcept. You have to plan out the objects of your web site for future integration/expansion. Another web app or web site cannot interact with your content if it doesn't follow the proper use-case.

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

IE and Firefox are two different beasts. There are a lot of things that IE allows that Firefox and other standards-aware browsers reject.

IE 和 Firefox 是两种不同的野兽。有很多 IE 允许 Firefox 和其他标准感知浏览器拒绝的东西。

If you're trying to create buttons without actually submitting data then use a combination of DIV/CSS.

如果您尝试创建按钮而不实际提交数据,请使用 DIV/CSS 的组合。

回答by ImagineCustoms

<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>

Try that. Unless you truly need to stick with the type as submit, then what I provided should work. If you are going to stick with submit, then everything mentioned above is correct, it makes no sense.

试试那个。除非你真的需要坚持提交类型,否则我提供的应该有效。如果你要坚持提交,那么上面提到的一切都是正确的,这是没有意义的。

回答by Mayk

You can do do it. The input type submit should be inside of a form. Then all you have to do is write the link you want to redirect to inside the action attribute that is inside the form tag.

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