JS为页面输入框做Check







<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>NewUserRight</title>
<link href="../html/pic/images/style.css" rel="stylesheet" type="text/css" />
<script language="javascript">
    function JumpSubmit() {
    alert("Creat User Failed...Please Try Again!!!");
        window.location.replace("../cgi-bin/user");
    window.parent.leftFrame.location = "../cgi-bin/usermainleft";
    }
    function JumpBack() {       
        window.location.replace("../cgi-bin/user");
    window.parent.leftFrame.location = "../cgi-bin/usermainleft";
    }
    function LoadOn(){
      document.getElementById("usernoerrorimg").style.visibility = "hidden";/**visible**/
      document.getElementById("usernameerrorimg").style.visibility = "hidden";/**visible**/
      document.getElementById("passwordfirsterrorimg").style.visibility = "hidden";/**visible**/
      document.getElementById("passwordseconderrorimg").style.visibility = "hidden";/**visible**/
      document.getElementById("submitbutton").disabled = true;
    }
    function BlurOn(textidname, picidname){
      if(document.getElementById(textidname).value == ""){

    document.getElementById(picidname).style.visibility = "visible";

      }
    }
    function CheckInput(inputid, errorimgid){
     

      var regu= /^([a-zA-Z0-9]|[._]){4,10}$/;



      if(document.getElementById(inputid).value != "" && regu.exec(document.getElementById(inputid).value) != null){

    document.getElementById(errorimgid).style.visibility = "hidden";

      }else{

    document.getElementById(errorimgid).style.visibility = "visible";

        document.getElementById("submitbutton").disabled = true;

      }

      

      if(document.getElementById("secondpasswordtext").value != document.getElementById("firstpasswordtext").value){

    document.getElementById("submitbutton").disabled = true;

    document.getElementById("passwordseconderrorimg").style.visibility = "visible";

      }else if(document.getElementById("secondpasswordtext").value == document.getElementById("firstpasswordtext").value &&
    regu.exec(document.getElementById("secondpasswordtext").value) != null){
    document.getElementById("passwordseconderrorimg").style.visibility = "hidden";

      }


      var inputtages = document.getElementsByTagName("input");

      var countflag = 0;

      

      for(var i = 0; i<inputtages.length; i++){

    if((inputtages[i].type == "password" || inputtages[i].type == "text") && inputtages[i].value != ""){

      countflag++;

    }

    if(countflag == 4 && document.getElementById("firstpasswordtext").value == document.getElementById("secondpasswordtext").value &&
          regu.exec(document.getElementById("usernotext").value) != null &&
          regu.exec(document.getElementById("usernametext").value) != null &&
          regu.exec(document.getElementById("firstpasswordtext").value) != null &&
          regu.exec(document.getElementById("secondpasswordtext").value) != null){

      document.getElementById("submitbutton").disabled = false;

    }

      }
    }
</script>
</head>

<body οnlοad="LoadOn();">
<form id="newuserform" name="newuserform" action="../cgi-bin/newuser" method="POST">
<div style="border: 6px ridge #00AAEC; background-color: #E7EEF6; height: 473px;">
      <ul>
    <li style="margin: 10pt; text-align: center; text-indent: -100px;">用 户 NO.:<span style="word-spacing: 50px;"> </span>
      <input type="text" id="usernotext" style="height: 20px; width: 130px;border:2px solid #bfd8e0;" οnblur="BlurOn('usernotext', 'usernoerrorimg');" οnkeyup="CheckInput('usernotext', 'usernoerrorimg');"/>
      <img id="usernoerrorimg" src="../html/pic/images/icon/error.png" />
    </li>
        <li style="margin: 10pt; text-align: center; text-indent: -100px;">用户名称:<span style="word-spacing: 50px;"> </span>
      <input type="text" id="usernametext" style="height: 20px; width: 130px;border:2px solid #bfd8e0;" οnblur="BlurOn('usernametext', 'usernameerrorimg');" οnkeyup="CheckInput('usernametext', 'usernameerrorimg');" />
      <img id="usernameerrorimg" src="../html/pic/images/icon/error.png" />
    </li>
    <li style="margin: 10pt; text-align: center; text-indent: -100px;">用户密码:<span style="word-spacing: 50px;"> </span>
      <input type="password" id="firstpasswordtext" style="height: 20px; width: 130px;border:2px solid #bfd8e0;" οnblur="BlurOn('firstpasswordtext', 'passwordfirsterrorimg');" οnkeyup="CheckInput('firstpasswordtext', 'passwordfirsterrorimg');" />
      <img id="passwordfirsterrorimg" src="../html/pic/images/icon/error.png" />
    </li>
    <li style="margin: 10pt; text-align: center; text-indent: -100px;">密码确认:<span style="word-spacing: 50px;"> </span>
      <input type="password" id="secondpasswordtext" style="height: 20px; width: 130px;border:2px solid #bfd8e0;" οnblur="BlurOn('secondpasswordtext', 'passwordseconderrorimg');" οnkeyup="CheckInput('secondpasswordtext', 'passwordseconderrorimg');" />
      <img id="passwordseconderrorimg" src="../html/pic/images/icon/error.png" />
    </li>
      </ul>
    <div ><input type="submit" value="确定" id="submitbutton"
            style="border: 5px outset #ECEADE; width: 50px; height: 30px; margin-left: 290px; background-color: #808080;" οnclick="JumpSubmit()"/>
      <input type="button" value="返回"
            style="border: 5px outset #ECEADE; width: 50px; height: 30px; margin-left: 100px; background-color: #808080;" οnclick="JumpBack()"/></div>
  </div>

  <br><div class="message-nonedisplaywarning">messageflag</div>
</body>
</html>







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值