2017-12-03 57 views
1

財產子,我有我下面的代碼這是給錯誤如下:無法讀取的不確定

Cannot read property substring of undefined (Uncaught type error) 

下面是我的代碼,我無法找出什麼是錯在這裏?

function cmt_btnsave(img) { 
    $img = $(img); 
    $this = $($img.prop('id').replace('img', 'txt')); //get textarea 
    saveComments($this, true); 
} 

function saveComments($this, isFinal) { 
    var controllerFuncParams = new Object(); 
    controllerFuncParams.sat = "@asi.sat"; 
    controllerFuncParams.s = "@asi.s"; 
    controllerFuncParams.sor = "@asi.sor"; 

    // this line is throwing exception 
    controllerFuncParams.c = $this.val().substring(0, "@charmax_eleComment"); 
    ...... 
} 

我不知道這裏有什麼問題?任何想法可能是錯的?

回答

0

看來你還沒有檢查$this.val()爲空。

if($this.val()){ 
controllerFuncParams.c = $this.val().substring(0, "@charmax_eleComment"); 
}