我正在使用这个 jQuery 片段在 html 表中的一些 JSF primefaces 元素上创建工具提示。
$(document).ready(function() {
$('.ui-icon-pencil, .ui-icon-check, .ui-icon-close, .ui-icon-trash').hover(function(e) { // this is the hover in function
// Since the elements have multiple classes, this function gets the one that starts with ui-icon-<something>
var icon = $(this).attr('class').match(/ui-icon-(?:pencil|check|close|trash)/)[0];
var title = null;
if(icon == 'ui-icon-pencil') {
title = 'Edit';
} else if(icon == 'ui-icon-check') {
title = 'Save';
} else if(icon == 'ui-icon-close') {
title = 'Cancel';
} else if(icon == 'ui-icon-trash') {
title = 'Delete';
}
$('body').append('<p class="tooltip">'+title+'</p>');
$('.tooltip').css('top', (e.pageY-50) + 'px').css('left', (e.pageX-10) + 'px').fadeIn('fast');
}, function() { // this is the hover out function
$('.tooltip').remove();
});
// this handles the tooltip moving when the mouse moves
$('.ui-icon-pencil').mousemove(function(e) {
$('.tooltip').css('top', (e.pageY-50) + 'px').css('left', (e.pageX-10) + 'px');
});
});
这很好用,除非您通过 jsf ajax 魔术修改/添加/删除表中的一行,工具提示将停止工作。
修改/添加/删除表格中的一行后,如何保持工具提示正常工作?
我认为我应该使用 jquery 的实时功能来保持工具提示的工作,但我不确定在这种情况下我将如何使用它们。