最基本的方法是将 JavaScript 设置window.location
为该 URL。
<input class="textbox" type="text" id="userid" />
<a href="javascript:window.location='access.jsp?userid=' + encodeURIComponent(document.getElementBy('userid'))">link</a>
或者
<input class="textbox" type="text" id="userid" />
<a href="#" onclick="window.location='access.jsp?userid=' + encodeURIComponent(document.getElementBy('userid'))">link</a>
但是,通常的方法是为此使用一个表单,这样参数在 URL 中“自动”结束,而不需要基于 JS 的讨厌的 hack/解决方法:
<form action="access.jsp">
<input class="textbox" type="text" name="userid" />
<input type="submit" value="submit" />
</form>
如果您主要关心按钮的样式,只需添加一些 CSS 使其看起来像一个链接。
请注意,这一切都与 JSP 完全无关,因为它只是一个 HTML/CSS/JS 代码生成器。在其他也产生 HTML/CSS/JS 的服务器端视图技术(例如 PHP、ASP 等)中,您会遇到完全相同的问题。