我有一个选择列表#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>
如果您使用选中的默认值点击提交然后更改它,则不会清除错误。 感谢
答案 0 :(得分:0)
您还应该使用value
来获取传递的值
if (value == '0')