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可能会有所不同,具体取决于网站上常规链接的样式。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…