我正在为表格中的单元格实现工具提示,我需要能够获取目标的data-message
属性。
$("#pricing_plans_table .sku_tooltip").tooltip({
// each trashcan image works as a trigger
tip: '#' + $(this).attr('data-message'),
// move tooltip a little bit to the right
offset: [0, 15],
// there is no delay when the mouse is moved away from the trigger
delay: 0
});
这不起作用。我得到“无法找到[object Object]的工具提示”......我不太确定如何正确引用目标。
答案 0 :(得分:1)
我不确定你是如何在tooltip
插件中执行此操作的,但是你可以使用.each()
循环获取值并为每个元素初始化tooltip
插件(在此内部无论如何都是插件可能会这样做:
$("#pricing_plans_table .sku_tooltip").each(function (index, value) {
var $this = $(this);
$this.tooltip({
tip : '#' + $this.attr('data-message'),
offset : [0, 15],
delay : 0
});
});
答案 1 :(得分:0)
我认为你不能在地图中使用this
。尝试:
$("#pricing_plans_table .sku_tooltip").each(function(i,el) {
var tipstr = $(this).attr('data-message');
$(this).tooltip({
tip: '#' + tipstr,
offset: [0, 15],
delay: 0
});
});