Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

html - 如何使输入类型=按钮像超链接一样使用get请求重定向? [重复](How to make an input type=button act like a hyperlink and redirect using a get request? [duplicate])

This question already has an answer here:

(这个问题在这里已有答案:)

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

(如何使<input type=button>像超链接一样使用GET请求进行重定向?)

  ask by Blankman translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

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

(即使没有打开javascript,这也具有工作的优势。)

Second, use a stand-alone button with javascript:

(其次,使用带有javascript的独立按钮:)

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

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

(然而,这在没有JavaScript的浏览器中会失败(注意:这是非常糟糕的做法 - 你应该使用事件处理程序,而不是像这样的内联代码 - 这只是说明我正在讨论的事情的最简单的方法。))

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.

(这样做的好处是可以在任何地方工作, 并且意味着您最想要的意思。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...