Angularjs 无法读取未定义的属性子字符串
我有下面的代码,错误如下:Angularjs 无法读取未定义的属性子字符串,angularjs,Angularjs,我有下面的代码,错误如下: 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);
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");
......
}
我不确定这里出了什么问题?有什么想法吗?似乎您没有检查
$this.val()
是否为空
if($this.val()){
controllerFuncParams.c = $this.val().substring(0, "@charmax_eleComment");
}