jsp中有两个按钮如何知道单击的是哪个按钮,JSP
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<body style="background-color:black;">
<p>
<p><input type="button" name="good" value="Pen" onclick="location.href='hello';"> </p>
<p><input type="button" name="good" value="Paper" onclick="location.href='hello';">
</p>
</body>
</html>
这是servlet
package pack.exp;
import java.io.IOException;
import javax.servlet.http.*;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
@SuppressWarnings("serial")
public class HelloServlet extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws
IOException
{
String val=req.getParameter("good");
if("Pen".equals(val))
{
resp.setContentType("text/plain");
resp.getWriter().println("Pen was clicked");
}
else if("Paper".equals(val))
{
resp.setContentType("text/plain");
resp.getWriter().println("Paper was clicked");
}
}
}
我的代码是不是给上点击按钮正确的输出。我想当我点击笔,然后它应该输入if()和打印文本,我想为纸张按钮相同。
嘿,我没有JQuery的知识。你能解释一下吗? – Sandeep
如果您只想使用html,则需要使用单选按钮。我不确定是否有其他方法。 jquery很容易使用。你正确的复制粘贴我的jQuery代码到HTML的脚本标签。 供参考,你可以参考一个示例jquery示例。 [jquery示例Click Me](http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_hide)请点击此链接。 – Bharathi