是onsubmit吧,这应该没有问题
我直接打开这个页面的话,onclick是可以执行的,就是经过后台处理跳转回来的时候就不行了,求大神帮忙!!
你发一个完整代码吧,包括跳转的页面,这没有onclick
login.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta charset="utf-8">
<script type="text/javascript">
function check()
{
var account=document.getElementById("user.idnumber");
var password=document.getElementById("user.password");
if(account.value=="")
{
alert("请输入用户名");
return false;
}
else if(password.value=="")
{
alert("请输入密码");
return false;
}
else
return true;
}
然后通过struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
/login.jsp
跳转到userAction.java中
public String Login(){
return "success";
}
当再次跳转到login.jsp中时
<form action="login" method="post" onsubmit="return check()">中onsubmit不起作用了
之前是我搞错了,确实是没有onclick
辛苦你了
我发现,如果没有下面那段代码的话,是可以实现onsubmit的,加上的话,就不可以了,是不是jQuery mobile的问题啊??
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>