如何获取jquery.qtip2选择的元素的属性值

How to get attribute values of the element that jquery.qtip2 selects

我的 html 文档如下所示:

<span class="mytooltip" id="P21_12" waarde="56"><img...></span>

我想将 idwaarde 属性的值传递给检索工具提示文本的函数。如果我对值进行硬编码,它会起作用:

  $('.mytooltip').qtip({
    content: { text : get_tooltip_text("P21_12","56") }
});

但是当我尝试访问属性值时,函数传递的是空值。

  $('.mytooltip').qtip({
    content: { text : get_tooltip_text($(this).attr("id"),$(this).attr("waarde")) }
});

我一定是哪里做错了。

我猜 this 不见了.. 你可以 运行 一个 each 循环然后这样做:

$('.mytooltip').each(function() {
    var id = this.id,
        attr = this.getAttribute("waarde"),
        text = get_tooltip_text(id, attr);

    $(this).qtip({
        content: { text : text }
    });
});