jQuery自定义验证方法问题 [英] jQuery custom validation method issue

查看:71
本文介绍了jQuery自定义验证方法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选择列表,默认值(对于请选择")为0.这是由于付款处理系统所致,超出了我的控制范围.我有一个add.Method,指出select的值是否为"0",则返回false,否则返回true.它可以正常工作,除了在提交并得到错误后将选择的值更改为其他值时,错误消息仍会显示.我该如何解决

I have a select list that's default value (for Please Select) is 0. this is due to the payment processing system and beyond my control. I have an add.Method that states if the select's value is "0" return false, otherwise return true. It works ok, except that when you change the select's value to something else after submitting and getting error, the error msg is still displayed. How do I fix this

HTML:

<form action="" method="post" id="SinglePmnt">
    <td>
     <select name="technology" class="select" id="singleTech">
      <option value="0" selected="selected">&nbsp;Please Select</option>
      <option value="Interactive Brokers">&nbsp;Interactive Brokers</option>
      <option value="MB Trading">&nbsp;MB Trading</option>
      <option value="Patsystems">&nbsp;Patsystems</option>
      <option value="PFG">&nbsp;PFG (Peregrine Financial)</option>
      <option value="TD AMERITRADE">&nbsp;TD AMERITRADE</option>
      <option value="Trading Technologies">&nbsp;Trading Technologies</option>
      <option value="Vision Financial Markets">&nbsp;Vision Financial Markets</option>
      <option value="Hosted">&nbsp;Zen-Fire</option>
     </select>
    </td>
    <td>Single Payment of $995</td>
    <td>
      <input type="hidden" name="item_number" value="34">
      <input type="submit" value="" class="orderNow" />
    </td>
</form>

使用jquery.validate.js的验证规则

the validation rule using jquery.validate.js

$(document).ready(function() {
        $.validator.addMethod(
            "SelectTechnology",
            function(value, element) {
                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"));
            }
        });
    });

在此看不到错误,非常感谢您的帮助. 谢谢

Can't see the error in this, I appreciate any help. thanks

推荐答案

在模糊事件中尝试强制验证.

Try forcing validation in the blur event.

$('#singleTech').click(function() {
  $('#SinglePmnt').validate().element('#singleTech');
});

$('#singleTech').blur(function(){
  $('#SinglePmnt').validate().element('#singleTech');
});

< select>上的jQuery change()和Firefox

您之前发布的实时链接似乎可以在IE中使用,但不适用于FireFox.

The live link you posted earlier seems to work in IE, but not FireFox.

这篇关于jQuery自定义验证方法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆