2009-08-18 119 views
1

這是問題的第二部分:jQuery工具提示彈出窗口重新插入標題值 - 工作是的!

在關閉彈出窗口時,我需要在彈出鏈接被點擊前重新插入title =「」值到原始值。彈出使用標題=「」值,在彈出的顯示,並從原來的標籤去掉它,好像有人懸停在鏈接不是在提示顯示。

的JS

this.contactPreview = function() { 
jQuery("a.contact").live('click', function(e){ 
     //store clicked link 
     var $this = jQuery(this); 
     //store title 
     var title = $this.attr('title'); 
     //remove title 
     $this.attr('title', ''); 

     //tip !== "" ? "<br />" + title : "";          

     jQuery("body").append("<p id='contact-info'>" + title + "<a id='close-contact' class='close-contact' style='color:red;'>Close</a></p>"); 

     //store reference to anchor and persist title on close-contact anchor 
     jQuery('#close-contact').data('anchor', $this).data('title', title); 

     jQuery("#contact-info").css("top", (e.pageY - xOffset) + "px") 
           .css("left", (e.pageX + yOffset) + "px") 
           .fadeIn(500); 
    }); 

    jQuery("#close-contact").live('click', function(){ 
     //store clicked link 
     var $this = jQuery(this); 
     //get anchor  
     var $anchor = $this.data('anchor'); 
     //get title 
     var title = $this.data('title'); 
     //set anchors title back 
     $anchor.attr('title', title);    
     //remove tip 
     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='this is what is in the popup'>Display popup</a> 
再次

感謝所有;)

回答

1

不需要隱藏字段。您可以使用.data來保存信息。此外,我還利用所有主播點擊進行了現場直播。 1時,不需要x dom事件。

this.contactPreview = function() { 
    jQuery("a.contact").live('click', function(e){ 
      //store clicked link 
      var $this = $(this); 
      //store title 
      var title = $this.attr('title'); 
      //remove title 
      $this.attr('title', ''); 

      tip !== "" ? "<br />" + title : ""; 

      jQuery("body").append("<p id='contact-info'>" + title + "<a id='close-contact' class='close-contact' style='color:red;'>Close</a></p>"); 

      //store reference to anchor and persist title on close-contact anchor 
      $('#close-contact').data('anchor', $this) 
           .data('title', title); 

      jQuery("#contact-info").css("top", (e.pageY - xOffset) + "px") 
            .css("left", (e.pageX + yOffset) + "px") 
            .fadeIn(500); 
     }); 

     jQuery("#close-contact").live('click', function(){ 
      //store clicked link 
      var $this = $(this); 
      //get anchor  
      var $anchor = $this.data('anchor'); 
      //get title 
      var title = $this.data('title'); 
      //set anchors title back 
      $anchor.attr('title', title);    
      //remove tip 
      $this.parent.remove();   
     }); 
    }; 
+0

Hi和感謝名單,只是一個問題,這樣的:(提示== 「
」 +標題: 「 」?「」 )不工作。提示說沒有定義提示錯誤。 還需要使用,而不是$的jQuery但那不是什麼大不了的 – 2009-08-19 12:48:00

+0

由於得到它的工作的,將張貼工作代碼:) – 2009-08-19 12:53:27

+0

你應該已經離開了原來的問題,並可以加入和你一起去解決一個更新位對於。很高興工作。 – redsquare 2009-08-19 12:57:39

相關問題