繁体   English   中英

callback.call不是一个函数

[英]callback.call is not a function

我收到此错误,并且很难纠正它。 我收到以下错误消息: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 );

提前致谢。

谢谢您的帮助。 事实证明这很简单。 我试图将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.... 

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

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

注意$("#first_name")会通过JQuery对象传递,该对象代表ID为#first_name的元素,而不仅仅是字符串"#first_name"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM