关于页面CHECK的问题 //文本框键盘事件function fnOnKeyPress(){ var obj = document.all.input //文本框对象 if ((event.keyCode < 45 || event.keyCode > 57) && (obj.value.length<=8)) event.returnValue = false;} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><TITLE> New Document </TITLE><META NAME="Generator" CONTENT="EditPlus"><META NAME="Author" CONTENT=""><META NAME="Keywords" CONTENT=""><META NAME="Description" CONTENT=""></HEAD><BODY><FORM METHOD=POST ACTION=""><INPUT TYPE="text" NAME="pwd1"><INPUT TYPE="text" NAME="pwd2"><INPUT TYPE="button" name="test" value="测试" onclick="return CheckPwd('pwd1','pwd2');"></FORM></BODY></HTML><SCRIPT LANGUAGE="JavaScript"><!--//检测密码是否一致function CheckPwd(val1,val2){ var pwd1=document.forms[0].elements[val1].value; var pwd2=document.forms[0].elements[val2].value; var reg =/[0-9]+$/; if(!reg.test(pwd1)) { alert("请输入数字"); document.forms[0].elements[val1].focus(); return false; } if (pwd1.length!=8) { alert('密码长度必须必须是8位!'); document.forms[0].elements[val1].focus(); return false; } if(!reg.test(pwd2)) { alert("请输入数字"); document.forms[0].elements[val2].focus(); return false; } if (pwd2.length!=8) { alert('密码长度必须必须是8位!'); document.forms[0].elements[val2].focus(); return false; } if (pwd1!=pwd2) { alert("两次密码输入不一致!"); document.forms[0].elements[val1].focus(); //document.forms[0].elements[val1].value=""; //document.forms[0].elements[val2].value=""; return false; } return true;}//--></SCRIPT> 这个应该可以,我是测试了通过了的:<html><head><title>check password</title></head><script language="javascript">function checknumeric(el){ //如果含有非字母数字 返回 true var text1="1234567890"; for(i=0;i<=el.length-1;i++) { char1=el.charAt(i); index=text1.indexOf(char1); if(index==-1){ return false;//非法 } //没有 } return true;}function checkpass(){if(checknumeric(document.form1.password.value)&&checknumeric(document.form1.confmpassword.value)&& (document.form1.confmpassword.value.length==8)&& (document.form1.password.value.length==8)&&(document.form1.password.value == document.form1.confmpassword.value)){alert("大侠,密码合格");return true;}else {alert("对不起,你的密码不合格");return false;}}</script><body><form name="form1" action="#" method="post">input password<input type='text' name='password' value=""><br>confirmpassword<input type='text' name='confmpassword' value=""><br><input type="button" name="button" value="checkpassword" onclick="javascript:checkpass()"></form></body></html> 怎样自定义jquery的方法 [JQuery]出现一个奇怪的问题,XYTipsWindow 2.8,好心人帮忙看看..... web前台程序功能:如何让在非默认打印机上进行打印 急求 JavaScript 获取iframe内容?急求 DOM特定属性只有函数才可以调用?(原理?) 怎么实现像360口袋收藏那样的右键添加收藏的功能? 100分打听一js日历控件的名字 高难度问题? 树形菜单问题 高分请教,不够再加:怎样实现网页数据实时动态更新? 为什么会这样? 自己动手写一个拼图游戏
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD><BODY>
<FORM METHOD=POST ACTION="">
<INPUT TYPE="text" NAME="pwd1">
<INPUT TYPE="text" NAME="pwd2">
<INPUT TYPE="button" name="test" value="测试" onclick="return CheckPwd('pwd1','pwd2');">
</FORM>
</BODY>
</HTML>
<SCRIPT LANGUAGE="JavaScript">
<!--
//检测密码是否一致
function CheckPwd(val1,val2)
{
var pwd1=document.forms[0].elements[val1].value;
var pwd2=document.forms[0].elements[val2].value;
var reg =/[0-9]+$/;
if(!reg.test(pwd1))
{
alert("请输入数字");
document.forms[0].elements[val1].focus();
return false;
}
if (pwd1.length!=8)
{
alert('密码长度必须必须是8位!');
document.forms[0].elements[val1].focus();
return false;
}
if(!reg.test(pwd2))
{
alert("请输入数字");
document.forms[0].elements[val2].focus();
return false;
}
if (pwd2.length!=8)
{
alert('密码长度必须必须是8位!');
document.forms[0].elements[val2].focus();
return false;
}
if (pwd1!=pwd2)
{
alert("两次密码输入不一致!");
document.forms[0].elements[val1].focus();
//document.forms[0].elements[val1].value="";
//document.forms[0].elements[val2].value="";
return false;
}
return true;
}
//-->
</SCRIPT>
<html><head>
<title>check password</title>
</head>
<script language="javascript">
function checknumeric(el)
{
//如果含有非字母数字 返回 true
var text1="1234567890";
for(i=0;i<=el.length-1;i++)
{
char1=el.charAt(i);
index=text1.indexOf(char1);
if(index==-1){
return false;//非法
}
//没有
}
return true;
}
function checkpass()
{
if(checknumeric(document.form1.password.value)&&checknumeric(document.form1.confmpassword.value)&& (document.form1.confmpassword.value.length==8)&& (document.form1.password.value.length==8)&&(document.form1.password.value == document.form1.confmpassword.value))
{
alert("大侠,密码合格");
return true;
}
else {
alert("对不起,你的密码不合格");
return false;
}
}
</script>
<body>
<form name="form1" action="#" method="post">
input password<input type='text' name='password' value="">
<br>
confirmpassword<input type='text' name='confmpassword' value="">
<br>
<input type="button" name="button" value="checkpassword" onclick="javascript:checkpass()">
</form>
</body></html>