zoukankan      html  css  js  c++  java
  • jquery validate 自定义验证方法(不固定验证)

    //自定义验证输入价格
    jQuery.validator.addMethod("PriceCheck", function (value, element) {
        var breakNumber=0;
        $(".producPrice").each(function (k, v) {
            if ($.trim($(v).val()) == "") {
                $(v).focus();
                breakNumber++;
                return false;
            }
        });
    
        if(breakNumber>0){
        return false;
        }else{
        return true;
        }
    
    }, "请输入价格");
    <table cellspacing="0" border="0" style="border-collapse:collapse;">
    <
    tbody>
    <
    tr>
    <
    td style="text-align: right;">445</td>
    <
    td style="text-align: left;"><input type="text" class="form-control producPrice" placeholder="价格" id="txtPrice" name="txtPrice" pid="1"></td>
    </
    tr>
    <
    tr>
    <
    td style="text-align: right;">test</td>
    <
    td style="text-align: left;"><input type="text" class="form-control producPrice" placeholder="价格" id="txtPrice" name="txtPrice" pid="3"></td>
    </
    tr>
    </
    tbody>
    </
    table>

    我生成了数个类样式为producPrice的输入框。

    验证:

    $("#form1").validate({
            rules: {
                txtLoginName: {
                    required: true
                    //remote: remoteHasAUserNameFun()
                }
                txtPrice:{
                    PriceCheck:true
                }
            },
            messages: {
                txtLoginName: {
                    required: "请输入账号"
                }
            },
            errorLabelContainer: $(".bg-info")
        });
  • 相关阅读:
    Problem B. Harvest of Apples
    字典树的学习
    PACM Team
    2038: [2009国家集训队]小Z的袜子(hose)
    Naive Operations
    C程序设计语言练习 第三章
    数据结构C++实现-第一章 绪论
    排序
    操作系统设计与实现-第一章:序言
    进制转换
  • 原文地址:https://www.cnblogs.com/hougelou/p/4200703.html
Copyright © 2011-2022 走看看