Pregunta

Aquí está el código jQuery para un emergente sobre herramientas cuando se ciernen sobre un enlace.

Error es cuando pasa sobre ella, se establece el título de mostrar nada se mostrará una vez y luego no se van a plantear si i re pasa sobre ella.

Cuando quito this.title = ""; funciona, pero el título del enlace aparece aswell

HTML

 < a href="#" class="tooltip" title="Name< br>Test">ToolTip< /a>

JQUERY

 this.tooltip = function(){ 

    xOffset = 10;
    yOffset = 20;               

$("a.tooltip").hover(function(e){                                             
    this.t = this.title;
    this.title = "";                                          
    $("body").append("<p id='tooltip'>"+ this.t +"</p>");
    $("#tooltip")
        .css("top",(e.pageY - xOffset) + "px")
        .css("left",(e.pageX + yOffset) + "px")
        .fadeIn("fast");        
},
function(){
    this.title = this.t;        
    $("#tooltip").remove();
}); 
$("a.tooltip").mousemove(function(e){
    $("#tooltip")
        .css("top",(e.pageY - xOffset) + "px")
        .css("left",(e.pageX + yOffset) + "px");
});         

};

¿Fue útil?

Solución

Usted desea realizar una comprobación de si el título está vacía primero. La razón por la cual se debe a que se está configurando la variable ciegamente t no importa qué y despejar el título. Prueba esto:

this.tooltip = function(){ 
    xOffset = 10;
    yOffset = 20;

    $("a.tooltip").hover(function(e){
        if(this.t === undefined || this.t.length == 0) {

           this.t = this.title;
           this.title = "";
        }
        $("body").append("<p id='tooltip'>"+ this.t +"</p>");
        $("#tooltip")
                .css("top",(e.pageY - xOffset) + "px")
                .css("left",(e.pageX + yOffset) + "px")
                .fadeIn("fast");
    }, function(){
        this.title = this.t;
        $("#tooltip").remove();
    }); 
    $("a.tooltip").mousemove(function(e){
        $("#tooltip")
                .css("top",(e.pageY - xOffset) + "px")
                .css("left",(e.pageX + yOffset) + "px");
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top