仅在JSP中单击按钮时运行脚本 [英] Run script only on button click in JSP
本文介绍了仅在JSP中单击按钮时运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是JSP的新手,我似乎无法弄清楚仅当用户单击按钮时如何运行代码.这是我的代码:
Iam new to JSP and i can't seem to figure out how to run code only when the user clicks on the button..here's my code:
$
<form action="list_computers.jsp" method="post">
Search:
<input type="text" name="FromTextBox1"/>
<input type="submit" value="Search it!" >
<%
String TheSearch = (String)request.getParameter("FromTextBox1");
String GetIt = Searcher(TheSearch);
out.println(GetIt);
%>
</form>
Searcher()是我在此之上声明的一个函数.任何帮助将不胜感激.
The Searcher() is a function i declared above this. Any help would be really appreciated.
推荐答案
您需要使用javascript来检查onclick事件,这是使用JQuery的一个小示例
you need to use javascript to check for the onclick event here's a little example with JQuery
$("input[type='submit']").click(function(){
//do your thing
// use event.preventDefault(); to stop submission if need
});
这篇关于仅在JSP中单击按钮时运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文