2017-12-03 13 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"); 
} 
関連する問題