提交表单前的用户名和密码为空校验
<form role="form" id="loginForm" action="${pageContext.request.contextPath }/system/user/login" method="post"> <fieldset> <div class="form-group"> <input class="form-control" placeholder="请输入用户名" name="username" type="text" value="" autofocus> </div> <div id="checkUsernameResult"/> <div class="form-group"> <input class="form-control" placeholder="请输入密码" name="password" type="password" value=""> </div> <div class="checkbox"> <label> <input name="remember" type="checkbox" value="remember">7天内自动登录<font color="red">(待开发)</font> </label> <span style="float: right;">验证码区域<font color="red">(待开发)</font></span> </div> <!-- Change this to a button or input when using this as a form --> <input type="submit" class="btn btn-lg btn-success btn-block" value="登录"/> <!-- <a href="index.html" class="btn btn-lg btn-success btn-block">登录</a> --> </fieldset> </form>
js:
$(function() { // 校验登录的用户名和密码的为空校验 $("#loginForm").bind("submit", function() { alert("用户名或密码不能为空!"); return false; }); }