问题描述
|
鼠标悬停在元素上时如何添加类?
var row = $(\'<tr></tr>\')
.append(\'<td class=\"list_row\">\'+js2txt(string)+\'</td>\')
.mouSEOver(function(){
this.addClass(\'list_row_mover\');
});
js错误:
this.addClass is not a function
解决方法
在您的函数中,作用域(
this
)是HTML元素,而不是jQuery对象。
这是一个可能的解决方法:
var row = $(\'<tr></tr>\')
.append(\'<td class=\"list_row\">\'+js2txt(string)+\'</td>\')
.mouseover(function(){
$(this).addClass(\'list_row_mover\');
});
,“ 2”返回没有功能“ 5”的DOM对象。相反,用户$(this)
指向具有功能addClass
的jQuery对象。
var row = $(\'<tr></tr>\')
.append(\'<td class=\"list_row\">\'+js2txt(string)+\'</td>\')
.mouseover(function(){
$(this).addClass(\'list_row_mover\');
});
,采用
$(this).addClass(\"list_row_mover\");
,您需要使用$(this)
,这是jquery对象。