zoukankan      html  css  js  c++  java
  • javascript 表单验证

    文章代码

    <form action="" method="post" name="form1" onsubmit="return check();"></form>

     提示:如果这里没有 return ,会检测,但还会跳转到 action='xxx.php'目标页面。  这样就是去了检测意义

    js代码

    function check(){
        if(form1.name.value ==""){
            alert("用户名不能为空");
            form1.name.focus();
            return false;
        }if(form1.pass.value.length <6){
            alert("密码长度未超过六位,请重新输入或者密码为空");
            form1.name.focus();
            return false;
        }if(form1.phone.value ==""){
            alert("电话不能为空");
            form1.phone.focus();
            return false;
        }if(form1.mobile.value.length !="11"){
            alert("手机不能为空或者输入错误");
            form1.mobile.focus();
            return false;
        }if(form1.email.value ==""){
            alert("邮箱不能为空");
            form1.email.focus();
            return false;
        }
    }

     提示:form.name 而不是form.id    跟input 的id没关系

    扩展

    1.history.back();

    2. 获取表单-》input的值

    function check(){
        $card = form1.card.value;
        alert($card);
    }
  • 相关阅读:
    substr函数
    Oracle 日期处理
    translate函数使用
    nvl函数
    random随机函数
    case语句
    列的拼接
    并行HASH JOIN小表广播问题
    WITH AS 优化逻辑读
    【hihoCoder挑战赛28 A】异或排序
  • 原文地址:https://www.cnblogs.com/wesky/p/3142282.html
Copyright © 2011-2022 走看看