我想在提交前在页面上验证用户名和密码非空。
若是为空则不能提交。
有什么办法吗?
新手、求解
最好是类似http://zc.qq.com/chs/index这样的提示的....
- JScript code
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>锦城之恋在线考试系统</title></head><body><marquee scrolldelay="500" scrollamount="100" bgcolor="ffaaaa" >欢迎来到XX系统</marquee> <table width="1002" height="400" border="0" align="center" cellpadding="0" cellspacing="0" ><form name="form1" method="POST" action="shenfen.jsp" ><p><span>身份:</span><select name="add" style="width:140;"> <option value="A" selected="selected">A</option> <option value="B">B</option> <option value="C">C</option></select></p>姓 名: <input type="text" name="name" style="width:140;" /><br>密 码: <input type="password" name="pwd" style="width:140;" /><br><input type="submit" value="登陆" /><input type="reset" value="重置" /></form></table></body></html>
------解决方案--------------------------------------------------------
- HTML code
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>锦城之恋在线考试系统</title><script> function check(f){ if( f.name.value == '' ){ alert('name is null') return false; } if( f.pwd.value == '' ){ alert('pwd is null') return false; } }</script></head><body><marquee scrolldelay="500" scrollamount="100" bgcolor="ffaaaa" >欢迎来到XX系统</marquee> <table width="1002" height="400" border="0" align="center" cellpadding="0" cellspacing="0" ><form name="form1" method="POST" action="shenfen.jsp" onsubmit="return check(this)"><p><span>身份:</span><select name="add" style="width:140;"> <option value="A" selected="selected">A</option> <option value="B">B</option> <option value="C">C</option></select></p>姓 名: <input type="text" name="name" style="width:140;" /><br>密 码: <input type="password" name="pwd" style="width:140;" /><br><input type="submit" value="登陆" /><input type="reset" value="重置" /></form></table></body></html>
------解决方案--------------------------------------------------------
用jQuery中的validation好啊
你也可以自己写,你找的那种样式就是增加一个失去焦点的事件(onblur)
- HTML code
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>锦城之恋在线考试系统</title></head><script type="text/javascript">function checkName(){ if(document.getElementById("name").value==""){ //这里写你要提示的操作 }}</script><body><marquee scrolldelay="500" scrollamount="100" bgcolor="ffaaaa" >欢迎来到XX系统</marquee> <table width="1002" height="400" border="0" align="center" cellpadding="0" cellspacing="0" ><form name="form1" method="POST" action="shenfen.jsp" ><p><span>身份:</span><select name="add" style="width:140;"> <option value="A" selected="selected">A</option> <option value="B">B</option> <option value="C">C</option></select></p>姓 名: <input type="text" name="name" id="name" value="" style="width:140;" onblur="checkName();"/><br>密 码: <input type="password" name="pwd" style="width:140;" /><br><input type="submit" value="登陆" /><input type="reset" value="重置" /></form></table></body></html>