jQuery bassistance验证,如何防止打印到console.log

时间:2012-06-11 09:16:15

标签: jquery jquery-validate

运行验证插件时,我可以看到它在Firebug中打印到控制台(即使我有debug: false)。

在IE9 / IE8中运行应用程序时,它会失败,除非在调试模式下,即shift + F12。在调试模式下,我可以看到它打印到IE控制台,应用程序实际工作。

如何配置插件以停止打印到控制台(我假设IE在不处于调试模式时无法处理)?或者这是验证插件中的错误,所以我必须自己删除这些行?

插件从插件的defaultShowErrors打印。

以下是验证码的示例:

function registerAccountValidation(){
    $("#registerform").validate({ 
        errorContainer: "#messageBox1",
        errorLabelContainer: "#messageBox1 ul",
        wrapper: "li", 
        debug:false,
        rules: {     
            owner_first_name: "required",
            owner_surname: "required",
            owner_email: { // compound rule 
                email: true,
                required: true,
                remote: "http://" + hostname +  "/modules/core/account/is_available.php"
            }, 
            email2: { 
                equalTo: "#email"
            },
            username: {
                required: true,
                remote: "http://" + hostname +  "/modules/core/account/is_available.php"
            },
            password: {
                required: true
            },
            password2: {
                equalTo: "#password"
            },                                
            owner_phone_number: "required",
            company_address: "required",
            zipcode: "required",
            city: "required",
            country: {
                required: true
            },
            company_name:{
                required: true,
                remote: "http://" + hostname +  "/modules/core/account/is_available.php"
            },
            company_link: {
                required: true,
                remote: "http://" + hostname +  "/modules/core/account/is_available.php",
                alpha: true
            }
        }, 
        messages: { 
            owner_first_name: {
                required: "First name is missing"
            },
            owner_surname: "Surname is missing",
            owner_email: { // compound rule 
                email: "Please specify a correct e-mail address" ,
                required: "E-mail is missing",
                remote: "E-mail address already registered"
            }, 
            email2: { 
                equalTo: "E-mail addresses must be equal"
            },
            username: {
                required: "Username is missing",
                remote: "Username is already registered"
            },
            password: {
                required: "Password is missing"
            },
            password2: {
                equalTo: "Passwords must be equal"
            },
            owner_phone_number: "Phone number is missing",
            company_address: "Address is missing",
            zipcode: "Zip code is missing",
            city: "City is missing",
            country: {
                required: "Country is missing"
            },
            company_name: {
                required: "Company name is missing",
                remote: "Company name already registered"
            },
            company_link: {
                required: "Link is missing",
                remote: "Link is already registered",
                alpha: "Must only contain a-z and A-Z and no blank space"
            }
        }
    }); 
}

更新

在插件中删除打印到控制台实际上解决了这个问题。但我更喜欢以正式方式进行,如果有的话。不希望在将来更新插件时遇到问题。

1 个答案:

答案 0 :(得分:0)

如果快速而肮脏的解决方案足够,您可以为没有真实解决方案的浏览器定义虚拟console.log:

if(!(window.console && window.console.log)){
    window.console = {
        log: function(){}
    };
}

如果发现实际问题很难证明,这至少会使错误消失。