jQuery $(this)问题,错误的对象

Fri*_*ons 0 jquery plugins

我用这段代码来显示标题

$(".line").mopTip({
'w':150, 
'style':"overOut", 
'get': $(this).attr("title")
});
Run Code Online (Sandbox Code Playgroud)

但作为标题,我得到了页面的标题......我错了什么?

amo*_*era 8

您正在使用this的内部文档窗口范围,这就是为什么它返回文档标题.要获得每一行的标题,您必须遍历每一行.

$(".line").each(function(){
    //inside the each the scope of this refers to the current line
    $(this).mopTip({
        'w':150, 
        'style':"overOut", 
        'get': $(this).attr("title")
    });
});
Run Code Online (Sandbox Code Playgroud)