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
149 views
in Technique[技术] by (71.8m points)

javascript - 使链接使用POST而不是GET(Make a link use POST instead of GET)

I'm not sure if this is even possible.

(我不确定这是否可能。)

But I was wondering if anyone knows how to make a hyperlink pass some variables and use POST (like a form) as opposed to GET.

(但是我想知道是否有人知道如何使超链接传递一些变量并使用POST(如表单)而不是GET。)

  ask by Elliot translate from so

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

1 Reply

0 votes
by (71.8m points)

You don't need JavaScript for this.

(您不需要JavaScript。)

Just wanted to make that clear, since as of the time this answer was posted, all of the answers to this question involve the use of JavaScript in some way or another.

(只是想说清楚一点,因为从发布此答案之时起,此问题的所有答案都涉及以某种方式使用JavaScript。)

You can do this rather easily with pure HTML and CSS by creating a form with hidden fields containing the data you want to submit, then styling the submit button of the form to look like a link.

(您可以使用纯HTML和CSS轻松地做到这一点,方法是创建一个包含要提交的数据的隐藏字段的表单,然后将表单的“提交”按钮样式化为链接。)

For example:

(例如:)

 .inline { display: inline; } .link-button { background: none; border: none; color: blue; text-decoration: underline; cursor: pointer; font-size: 1em; font-family: serif; } .link-button:focus { outline: none; } .link-button:active { color:red; } 
 <a href="some_page">This is a regular link</a> <form method="post" action="some_page" class="inline"> <input type="hidden" name="extra_submit_param" value="extra_submit_value"> <button type="submit" name="submit_param" value="submit_value" class="link-button"> This is a link that sends a POST request </button> </form> 

The exact CSS you use may vary depending on how regular links on your site are styled.

(您使用的确切CSS可能会有所不同,具体取决于网站上常规链接的样式。)


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

...