我有一个动态表,加载了ajax。我想当我将鼠标悬停在某个对象上时显示工具提示row,但我希望工具提示出现在某个特定的位置上cell(与类.name
)而不是在整行上方。
另外,使用 title 函数,我需要能够获取最接近的行 ID 并返回自定义模板。
这是我的代码:
<table class="table" id="myTable">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Country</th>
<th>Statistics</th>
</tr>
</thead>
<tbody>
<tr id="1">
<td >1</td>
<td class="name">Name #1</td>
<td>United States of America</td>
<td>100%</td>
</tr>
<tr id="2">
<td >2</td>
<td class="name">Name #2</td>
<td>United States of America</td>
<td>50%</td>
</tr>
</tbody>
</table>
初始化:
$('#myTable').tooltip({
container: 'body',
html: true,
selector: 'td.name',
trigger: 'manual',
title: function() {
// here will be custom template
var id = $(this).parent().atrr('id');
return id;
}
});
尝试一:jsFiddle 中的演示 http://jsfiddle.net/tLs3G/
$('#myTable')
.on('mouseenter focusin', 'tbody > tr', function() {
$(this).find('td.name').tooltip('show');
})
.on('mouseleave focusout', 'tbody > tr', function() {
$(this).find('td.name').tooltip('hide');
});
尝试二:jsFiddle 中的演示 http://jsfiddle.net/tLs3G/1/
var tip;
$('#myTable')
.on('mouseenter focusin', 'tbody > tr', function() {
tip = $(this).find('.offer-name');
tip.tooltip(hereAllTooltipOptions);
tip.tooltip('show');
})
.on('mouseleave focusout', 'tbody > tr', function() {
tip.tooltip('hide');
});
但我对这种解决方案的性能非常好奇。那么,问题是如何去做,并且做得更好?