Validform实时表单验证插件实例使用

文档日期:2016-10-17
适用范围:所有类型网站表单验证
插件版本:v5.3.2
插件地址:http://validform.rjboy.cn/Validform/v5.3.2/Validform_v5.3.2_min.js
jquery地址:http://download.csdn.net/detail/bennygreat/3861587

html中的代码实例

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="css/style.css">
    <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
    <script type="text/javascript" src="js/Validform_v5.3.2.js"></script>
</head>
<body>
    <div class="main">
        <div class="box">
            <form action="test.php" id="myForm">
                <ul>
                    <li>账号:
                        <input type="text" name="number" ajaxurl="number.php" datatype="s5-16" errormsg="昵称至少5个字符,最多16个字符!">
                        <div class="Validform_checktip"></div>
                    </li>
                    <li>密码:
                        <input type="password" name="password" datatype="*6-15" errormsg="密码范围在6~15位之间!">
                        <div class="Validform_checktip"></div>
                    </li>
                    <li>邮箱:
                        <input type="email" name="email" datatype="e" errormsg="邮箱格式不正确!">
                        <div class="Validform_checktip"></div>
                    </li>
                    <li>内容:
                        <textarea name="content" id="" cols="30" rows="10" tip="请在这里输入您的意见。" errormsg="很感谢您花费宝贵时间给我们提供反馈,请填写有效内容!"  datatype="s" altercss="gray"></textarea>
                        <div class="Validform_checktip"></div>
                    </li>
                    <li>性别:
                        <input type="radio" class="radio" name="sex" value='1' datatype="*" nullmsg="请选择性别!" errormsg="请选择性别!" ><input type="radio" class="radio" name="sex" value='0' ><div class="Validform_checktip"></div>
                    </li>
                    <li>
                        select:
                        <select name="select" datatype="*" nullmsg="请选择!" errormsg="请选择!" >
                            <option value="开启">开启</option>
                            <option value="关闭">关闭</option>
                        </select>
                        <div class="Validform_checktip"></div>
                    </li>
                    <li>爱好:
                        <input type="checkbox" class="check" name="hopoy[]" value="足球" datatype="*" nullmsg="请选择爱好!" errormsg="请选择性别!" >足球
                        <input type="checkbox" class="check" name="hopoy[]" value="篮球" >篮球
                        <input type="checkbox" class="check" name="hopoy[]" value="排球" >排球
                        <div class="Validform_checktip"></div>
                    </li>
                    <li><input type="submit" value="提交" class="btn"><input type="reset" value="重置" class="btn"></li>
                </ul>
                <div id="dump"></div>
            </form>
        </div>

    </div>

<script>
    $(function() {

        $("#myForm").Validform({
            tiptype:function(msg,o,cssctl){

                if(!o.obj.is("form")){
                    var objtip=o.obj.siblings(".Validform_checktip");
                    cssctl(objtip,o.type);
                    objtip.text(msg);
                }else{
                    var objtip=o.obj.find("#dump");
                    cssctl(objtip,o.type);
                    objtip.text(msg);
                }

            },
            ajaxPost:true
        });

    })
</script>
</body>
</html>

test.php文件代码实例

<?php

    sleep(3);

    if($_POST) {

        echo '{"info":"数据提交成功!","status":"y"}';

    }

?>

number.php代码实例

<?php
    sleep(1);
    if($_POST){

        if($_POST["param"] == "abc123"){
            echo '{"info":"用户名重复!","status":"n"}';
        }else{
            echo '{"info":"通过信息验证!","status":"y"}';
        }


    }
?>

style.css样式代码

/*全局注释*/
*{
    padding: 0px;
    marign:0px;
}
ul,li{
    list-style: none;
}
/*表单部分*/
.main{
    margin-top:30px; 
    background: #fff;
}

.main .box{
    width: 50%;
    margin: 0 auto;
}

.main .box ul li{
    margin-top: 5px;
}
.main .box ul li input{
    height: 20px;
    width: 140px;
}

.main .box ul li input.radio,.main .box ul li input.check{
    width: 13px;
    height: 13px;
}

/*固定文本框大小*/
.main .box ul li textarea{
    resize: none;
    width: 200px;
    height: 100px;
    max-width: 200px;
    max-height: 100px;
}

/*表单提交按钮*/
.main .box ul li input.btn{
    margin:5px; 
    width: 40px;
    height: 30px;
}

#dump{
    width: 50%;
    margin:10px auto;   
}

/*提示信息*/
.Validform_checktip{
    /*display: none;*/
    font-size: 14px;
    padding-left: 20px;
} 
.Validform_wrong{
    font-size: 14px;
    color: red;
    padding-left: 20px;
}
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

任聪聪

创作不易,你的打赏是我的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值