如何使输入类型=按钮的行为就像一个超链接,并使用GET请求重定向? [英] How to make an input type=button act like a hyperlink and redirect using a get request?

查看:137
本文介绍了如何使输入类型=按钮的行为就像一个超链接,并使用GET请求重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何做一个<输入类型=按钮> 像一个超级链接,并使用重定向 GET 要求?

How do I make a <input type=button> act like a hyperlink and redirect using a GET request?

推荐答案

有几种不同的方式来做到这一点 - 首先,简单地把它指向你想要它去一个表单中:

There are several different ways to do that -- first, simply put it inside a form that points to where you want it to go:

<form action="/my/link/location" method="get">
    <input type="submit" value="Go to my link location" 
         name="Submit" id="frm1_submit" />
</form>

这具有即使没有开启JavaScript工作的优势。

This has the advantage of working even without javascript turned on.

二,使用单独的按钮,使用javascript:

Second, use a stand-alone button with javascript:

<input type="submit" value="Go to my link location" 
    onclick="window.location='/my/link/location';" />       

然而,这将在浏览器中失败没有JavaScript(注:这是的真的是不好的做法 - 你应该使用的事件处理程序,而不是内嵌code这样的 - 这仅仅是说明那种我谈论事情的最简单方式。)

This however, will fail in browsers without JavaScript (Note: this is really bad practice -- you should be using event handlers, not inline code like this -- this is just the simplest way of illustrating the kind of thing I'm talking about.)

第三个选项是样式就像一个按钮,一个实际的链接:

The third option is to style an actual link like a button:

<style type="text/css">
.my_content_container a {
    border-bottom: 1px solid #777777;
    border-left: 1px solid #000000;
    border-right: 1px solid #333333;
    border-top: 1px solid #000000;
    color: #000000;
    display: block;
    height: 2.5em;
    padding: 0 1em;
    width: 5em;       
    text-decoration: none;       
}
// :hover and :active styles left as an exercise for the reader.
</style>

<div class="my_content_container">
    <a href="/my/link/location/">Go to my link location</a>
</div>

这在任何地方工作的优势这意味着你很可能希望它的意思。

This has the advantage of working everywhere and meaning what you most likely want it to mean.

这篇关于如何使输入类型=按钮的行为就像一个超链接,并使用GET请求重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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