求快乐,求高,潮!!!! 我想问的是注册页面的用户名注册中间要辨别用户输入是否合法,密码两次是否正确,用js写怎么弄?如果不合法在text后面提示错误信息怎么写?不喜欢alert,想要就在输入框后面提示。求大神指导,刚学js。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function regedit(){ if(document.getElementById("userName").value.length == 0){ document.getElementById("userNameNotice").innerHTML = "the userName can not be null!"; return false; } if(document.getElementById("userPwd").value.length == 0){ document.getElementById("userPwdNotice").innerHTML = "the userPwd can not be null!"; return false; } if(document.getElementById("userPwd1").value.length == 0){ document.getElementById("userPwdNotice1").innerHTML = "the userPwd1 can not be null!"; return false; } if(document.getElementById("userPwd").value != document.getElementById("userPwd1").value){ document.getElementById("pwd").innerHTML = "the two passwords you entered do not match!"; return false; }}------------------------------------------------------------------------------------<form action="" method="post"> <table> <tr> <td>userName:</td> <td><input type="text" name="userName" id="userName" value=""/></td> <td><font color="red" id="userNameNotice"></td> </tr> <tr> <td>userPwd:</td> <td><input type="password" name="userPwd" id="userPwd" value=""/></td> <td><font color="red" id="userPwdNotice"></td> </tr> <tr> <td>userPwd again:</td> <td><input type="password" name="userPwd1" id="userPwd1" value=""/></td> <td><font color="red" id="userPwdNotice1"></td> <td><font color="red" id="pwd"></td> </tr> <tr> <td colspan="2"> <input type="button" value="regedit" onclick="regedit()"> </td> </tr> </table> </form> 加个隐藏域,如果不对,就document.getElementById("hiddenId").innerHTML="xxxxxxxx"; jQuery 很好很强大的。 下面是js的 很不好用 <script type="text/javascript"> function mcheck(){ var name = document.getElementById("uname").value; if(null == name || "" == name){ document.getElementById("span0").innerHTML = "name is null"; } } </script> <body> name:<input id="uname" name="uname" onblur="mcheck()"><span id="span0" style="color:red">*</span></br> </body> <script type="text/javascript" src="js/jquery-1.4.2.js"></script></head> <script type="text/javascript"> function mcheck(){ var name = $("uname").value; if(null == name || "" == name){ $("#span0").html("name is null"); } } </script> <body> 文本框失去焦点 name:<input id="uname" name="uname" onblur="mcheck()"><span id="span0" style="color:red">*</span></br> </body> 可以用onsubmit事件 就可以了事件关联的方法里面写具体的操作js就可以了 jquery.validate.js 你可以试试。呵呵 推荐个验证框架给你:Form validation,自己google下,效果好,简单易用! 动不动就jquery,jquery没出生前这样的问题就没法解决了? 你可以先定义一下div,然后正如4楼写的,但是改造下,如果出错,你可以show出这个div,给这个div加上一个text,提示自己的错误信息。 关于hibernate的annotation 谁有用JSP写的上传图片的程序 poi 怎么就导出130条记录? 自定义表单资料 谁知道使用SQL Server数据库连接池的并使用JavaBean的数据库分页技术,万分感激。 Help me! sqlserver的text字段乱码????(搞不懂) 求助:整合apache2.0.43+tomcat4.1.12+mod_jk-2.0.42的问题 一个关于servlet和applet的简单问题 CCTV5解说世界杯的妞--1小时后揭贴 斑竹散分,希望大家继续支持jsp版 如何得到一个webserver是否支持P3P? webgis二次开发问题!!!
function regedit(){
if(document.getElementById("userName").value.length == 0){
document.getElementById("userNameNotice").innerHTML = "the userName can not be null!";
return false;
}
if(document.getElementById("userPwd").value.length == 0){
document.getElementById("userPwdNotice").innerHTML = "the userPwd can not be null!";
return false;
}
if(document.getElementById("userPwd1").value.length == 0){
document.getElementById("userPwdNotice1").innerHTML = "the userPwd1 can not be null!";
return false;
}
if(document.getElementById("userPwd").value != document.getElementById("userPwd1").value){
document.getElementById("pwd").innerHTML = "the two passwords you entered do not match!";
return false;
}
}
------------------------------------------------------------------------------------
<form action="" method="post">
<table>
<tr>
<td>userName:</td>
<td><input type="text" name="userName" id="userName" value=""/></td>
<td><font color="red" id="userNameNotice"></td>
</tr>
<tr>
<td>userPwd:</td>
<td><input type="password" name="userPwd" id="userPwd" value=""/></td>
<td><font color="red" id="userPwdNotice"></td>
</tr>
<tr>
<td>userPwd again:</td>
<td><input type="password" name="userPwd1" id="userPwd1" value=""/></td>
<td><font color="red" id="userPwdNotice1"></td>
<td><font color="red" id="pwd"></td>
</tr>
<tr>
<td colspan="2">
<input type="button" value="regedit" onclick="regedit()">
</td>
</tr>
</table>
</form>
<script type="text/javascript">
function mcheck(){
var name = document.getElementById("uname").value;
if(null == name || "" == name){
document.getElementById("span0").innerHTML = "name is null";
}
}
</script>
<body>
name:<input id="uname" name="uname" onblur="mcheck()"><span id="span0" style="color:red">*</span></br>
</body>
<script type="text/javascript">
function mcheck(){
var name = $("uname").value;
if(null == name || "" == name){
$("#span0").html("name is null");
}
}
</script>
<body>
文本框失去焦点
name:<input id="uname" name="uname" onblur="mcheck()"><span id="span0" style="color:red">*</span></br>
</body>
事件关联的方法里面写具体的操作js
就可以了