需要有关选择列表的jQuery验证帮助

时间:2010-09-29 18:40:06

标签: jquery

  

可能重复:
  jQuery custom validation method issue

我有一个选择列表#technology。由于后端支付处理器,它的默认值为“0”。我需要一个验证规则(使用jquery.validate.js),如果它的值为“0”则返回false,但对于任何其他值返回true。我正在尝试的是不起作用。

<script type="text/javascript">
    $(document).ready(function() {
        $.validator.addMethod(
            "SelectTechnology",
            function(value, element) {
                //var selectedCountry = $('#Country').val();
                if ($("#singleTech").val() === '0'){
                    return false;
                } else return true;
            },
            "Please Select a Technology"
        );
        var validator = $("#SinglePmnt").validate({
            rules: {
                    technology: {
                        SelectTechnology: true
                    }
            },
            errorElement: "span",
            errorPlacement: function(error, element) {
                error.appendTo(element.parent("td"));
            }
        });
    });
</script>

如果您使用选中的默认值点击提交然后更改它,则不会清除错误。 感谢

1 个答案:

答案 0 :(得分:0)

您还应该使用value来获取传递的值

if (value == '0')