我的button按钮的onclick事件调用JS里的方法怎么不触发
1个回答
展开全部
给你举一个简单的案例,在这个例子中,onclick用来判断用户名不可以为空,然后通过单击登陆按钮进行触发判断,仅供参考
<%@ page language="java" import="java.util.*,java.sql.*" contentType="text/html; charset=gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Insert title here</title>
<script language="javascript">
function checkNum()
{
if(form1.name.value=="")
{
window.alert("用户名不能为空");
return false;
}
}
</script>
</head>
<body>
<%
String s_name=request.getParameter("name");
String s_password=request.getParameter("password");
String c="未登录";
String s_select=request.getParameter("select");
String d="2";
if(s_name!=null&&s_password!=null)
{
Connection ct=null;
try{
//1加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
c="0";
//2得到连接
ct=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=ls","sa","123");
c="1";
//3创建Statement
Statement sm=ct.createStatement();
c="2";
//4查询
ResultSet rs=sm.executeQuery("select userId,password from login where name='"+s_name+"'");
c="3";
if(rs.next())
{
c="4";
c=rs.getString(2);
d=rs.getString(1);
if(rs.getString(2).trim().equals(s_password.trim()))
{
c="欢迎登陆";
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
%>
<center>
<h2>欢迎登陆服装连锁系统</h2>
</center>
<center>
<form name="form1" action="huanying.jsp">
登录身份:
<select name="select">
<option value="总店">总店</option>
<option value="分店">分店</option>
</select><br><br>
姓名:<input type="text" name="name" style="width:150px"><br>
密码:<input type="password" name="password" style="width:150px"><br>
<br><br>
<input type="submit" value="登陆" onclick="return checkNum();">
<input type="reset" value="取消"><br>
登录状态:<%=c %>
</center>
</form>
</body>
</html>
<%@ page language="java" import="java.util.*,java.sql.*" contentType="text/html; charset=gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Insert title here</title>
<script language="javascript">
function checkNum()
{
if(form1.name.value=="")
{
window.alert("用户名不能为空");
return false;
}
}
</script>
</head>
<body>
<%
String s_name=request.getParameter("name");
String s_password=request.getParameter("password");
String c="未登录";
String s_select=request.getParameter("select");
String d="2";
if(s_name!=null&&s_password!=null)
{
Connection ct=null;
try{
//1加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
c="0";
//2得到连接
ct=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=ls","sa","123");
c="1";
//3创建Statement
Statement sm=ct.createStatement();
c="2";
//4查询
ResultSet rs=sm.executeQuery("select userId,password from login where name='"+s_name+"'");
c="3";
if(rs.next())
{
c="4";
c=rs.getString(2);
d=rs.getString(1);
if(rs.getString(2).trim().equals(s_password.trim()))
{
c="欢迎登陆";
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
%>
<center>
<h2>欢迎登陆服装连锁系统</h2>
</center>
<center>
<form name="form1" action="huanying.jsp">
登录身份:
<select name="select">
<option value="总店">总店</option>
<option value="分店">分店</option>
</select><br><br>
姓名:<input type="text" name="name" style="width:150px"><br>
密码:<input type="password" name="password" style="width:150px"><br>
<br><br>
<input type="submit" value="登陆" onclick="return checkNum();">
<input type="reset" value="取消"><br>
登录状态:<%=c %>
</center>
</form>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询