jQuery工具提示无法按预期工作 - 已修订

时间:2009-08-18 19:16:46

标签: jquery function popup tooltip

好的我修复了原来的问题,但我想现在是在删除弹出窗口之前,从id =“contact-info”弹出窗口中将标题值添加回id =“contact”的锚标记

JS

this.contactPreview = function() {
jQuery("a.contact").click(function(e){
        this.t = this.title;
        this.title = "";
        var c = (this.t != "") ? "<br />" + this.t : "";
        jQuery("body").append("<p id='contact-info'>"+ this.t + "<a id='close-contact' class='close-contact' style='color:red;'>Close</a></p>");
        jQuery("#contact-info")
            .css("top", (e.pageY - xOffset) + "px")
            .css("left", (e.pageX + yOffset) + "px")
            .fadeIn(500);
    });

    jQuery("a.close-contact").live('click', function(){
        // Need to re-insert the popup info into the original title tag of contact
        jQuery('#contact-info').remove();          
    });
};

// Use jQuery() instead of $()for WordPress compatibility with the included prototype js library which uses $()
// http://ipaulpro.com/blog/tutorials/2008/08/jquery-and-wordpress-getting-started/
// See http://chrismeller.com/using-jquery-in-wordpress
jQuery(document).ready(function(){

    // Call the function here
    contactPreview();

});

CSS

#contact-info{
    position:absolute;
    border:1px solid #ccc;
    background:#333;
    padding:5px;
    display:none;
    color:#fff;

HTML

<a class='contact' title='Some info to display'>Display Info</a>

提前感谢您对此的任何帮助

1 个答案:

答案 0 :(得分:0)

http://docs.jquery.com/Events/live可以解决问题。

这将在创建CLOSE <A>时自动添加click事件。您所做的是在加载文档时添加了事件,但尚未加载CLOSE <A>

$("a.close-contact").live("click", function()
{
    $(this).fadeOut(500);
});