2017-12-03 135 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"); 
}