输入按钮上的 HTML 链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21350897/
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
HTML link on input button
提问by SuRaj Creator
I want to know how do i put link on input button in html pages. As of now i am trying to make a link on input button by putting hyperlinks around buttons but can it be possible with any other method to navigate to another page?
我想知道如何在 html 页面的输入按钮上放置链接。到目前为止,我正在尝试通过在按钮周围放置超链接来在输入按钮上创建链接,但是否可以使用任何其他方法导航到另一个页面?
curretly i am doing like this:
目前我正在这样做:
<html>
<head>
<title>Practise 20</title>
<style>
input[type="submit"]{border:none; background:#000; color:#fff}
</style>
<body>
Click on Button to navigate the Pages
<form>
<a href="http://www.google.com" target="self"><input type="submit" Value="Go"></a>
</form>
</body>
</html>
回答by SuRaj Creator
you can put link on input buttons by java script.. try like this
你可以通过java脚本在输入按钮上放置链接..试试这样
<html>
<head>
<title>Practise 20</title>
<style>
input[type="submit"]{border:none; background:#000; color:#fff}
</style>
</head>
<body>
Click on Button to navigate the Pages
<form>
<input onClick="window.location.href='put your page url here'" type="submit" Value="Go">
</form>
</body>
</html>
回答by Cristian D
You might get it to work better with a simple javascript.
你可能会用一个简单的 javascript 让它更好地工作。
<script type="text/javascript">
function google() {
window.location = "http://google.com";
}
</script>
And as of the HTML part:
从 HTML 部分开始:
<input type="submit" value="Go" onClick="google()">
回答by Quentin
I want to know how do i put link on input button in html pages?
我想知道如何在 html 页面的输入按钮上放置链接?
You don't. Links are links. Buttons are buttons. One cannot be placed inside the other in HTML.
你没有。链接就是链接。按钮就是按钮。在 HTML 中,一个不能放在另一个里面。
If you want a link that looks like a button, then use a link and apply CSS to make it look the way you want.
如果你想要一个看起来像一个按钮的链接,那么使用一个链接并应用 CSS 让它看起来像你想要的那样。
回答by gurudeb
<form action="http://www.google.com"><input type="submit" Value="Go"></form>
Please note that you should not use submit buttons for hyperlinking purpose. Submit button is for submitting a form, therefore linking it to a page send the wrong info to the user. Still you can do it; if you need to.
请注意,您不应将提交按钮用于超链接目的。提交按钮用于提交表单,因此将其链接到页面会向用户发送错误信息。你仍然可以做到;如果你需要。
回答by Mike.O
Attribute formactionworks pretty well. Here is an example:
属性形成效果很好。下面是一个例子:
<input type="submit" formaction="login.html" value="Submit to another page">
回答by d0rf47
You can definitely do this. You can have a form with a post action to the route, then use bootstrap classes to disguise the input as a nav link
你绝对可以做到这一点。您可以拥有一个带有路由后操作的表单,然后使用引导类将输入伪装为导航链接
<form action="/Rooms/Edit/:id" method="POST" style="margin: 0 1rem;">
<input class="btn btn-link" value="Edit Rooms" type="submit" style="font-weight: bold; text-dectoration:none">
</form>