2015-08-20 263 views
0

我得到這個錯誤,並且很難糾正它。我收到以下錯誤消息:callback.call不是函數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); 

在此先感謝。

+0

提供了哪些參數給checkLength調用? – Mahout

+0

(元素,字符串標籤,最小值,最大值)例如(「#first_name」,「名字」,3,30); – Michael

回答

0

根據您的評論,問題可能是checkLength的第一個參數是字符串而不是JQuery對象。看起來像電話應該更像

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

注穿過表示與ID #first_name而不僅僅是字符串"#first_name"的元素的jQuery對象的$("#first_name")

+0

我的歉意,第一個參數是一個jQuery對象,例如存儲在變量中的first_name = $(「#first_name」) – Michael

+0

你能解釋爲什麼你有'if(validateCheckBox(o)){validateCheckBox(o); }'? – Mahout

+0

關於if(validateCheckBox(o)){validateCheckBox(o); }我認爲這將防止錯誤即。如果validateCheckBox存在,則調用它,否則該函數將不會被調用。 – Michael

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....