callback.call不是一个函数

时间:2015-08-20 19:28:47

标签: javascript jquery jquery-ui

我收到此错误并且很难纠正错误。我收到以下错误消息:callback.call不是函数

我已在下面发布了代码段以供注释,似乎在调用validateCheckBox(o)时会触发错误。我理解错误是由一个脱离上下文的函数触发但不完全确定如何修复。

function checkLength( o, n, min, max ) {
    console.log( arguments.length );
    if ( arguments.length < 4 ) {   
        // issue here with callback.call is not a function
        if ( validateCheckBox(o) ){
            validateCheckBox(o);  
        }
    }else {
        if ( o.val().length > max || o.val().length < min ) {
        o.addClass( "ui-state-error" );
        updateTips( "Length of " + n + " must be between " +
          min + " and " + max + "." );
        return false;
      } else {
        return true;
      }

    }

}

function validateCheckBox( o ) {

    var css = $(".border").css({
                                "border-color": "",
                                "border-weight": "",
                                "border-style" : "",
                                "background-color": "",
                                "background-image": "",
                                "background-repeat":"",
                                "background-position":""
                            });
    //console.log(css);
    var invalidChkBox = {   
                        "border-color":"#cd0a0a",
                        "border-weight":"1px",
                        "border-style":"solid",
                        "background-color": "#feflec",
                        "background-image": "url('lib/jquery-ui/css/images/ui-bg_glass_95_fef1ec_1x400.png')",
                        "background-repeat": "repeat-x",
                        "background-position": "50% 50%"


            }

    // throwing error callback is not defined
    var isChecked = $( "#verification" ).is(":checked");

    if ( isChecked == false || isChecked == undefined ) {

        $( ".border"  ).css( invalidChkBox );
        o.addClass( "ui-state-error" );
        $( ".validateTips" ).text( "You must agree that all information is accurate and true, by checking the box." );

    }else{
        // reported bug callback.call is not a function @error below
        $( ".validateTips" ).css( 'display', null ).text( "" );
        $( ".border"  ).css( css );



    }


}

 valid = valid && checkLength ( verification, "Verification", 1 );

提前致谢。

2 个答案:

答案 0 :(得分:0)

根据您的评论,问题可能是checkLength的第一个参数是字符串而不是JQuery对象。看起来呼叫应该更像是

checkLength($("#first_name"), "First name", 3, 30 );

注意$("#first_name")通过表示id为#first_name的元素的JQuery对象,而不仅仅是字符串"#first_name"

答案 1 :(得分:0)

感谢您的帮助。事实证明这很简单。我试图用已经在其上定义的规则将css规则分配给类......

var css = $(".border").css({
                                "border-color": "",
                                "border-weight": "",
                                "border-style" : "",
                                "background-color": "",
                                "background-image": "",
                                "background-repeat":"",
                                "background-position":""
                            });
$( ".border"  ).css( css ); --> line throwing error....