【发布时间】:2014-09-18 08:15:46
【问题描述】:
我有一个动态表,加载了 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;
}
});
尝试一:Demo in jsFiddle
$('#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');
});
尝试二:Demo in jsFiddle
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');
});
但我非常想知道这种解决方案的性能。那么,问题是如何做到并做得更好?
【问题讨论】:
标签: jquery twitter-bootstrap twitter-bootstrap-3