2010-06-02 50 views
0

基本上我试图抓住链接中title属性的文本,并在用户悬停该项目时显示在另一个div中的paragaph中,并且然后在用户离开时隐藏它。到目前为止,我所得到的是从标题属性中获取文本并将其添加到jquery中的div

(function($) { 
    $.fn.showText = function() { 
     $(this).hover(
      function() { 
       $(this) 
        .data('title', $(this).attr('title')) 
        .removeAttr('title') 
     .appendTo(".itemDecription p"); 
      }, 
      function() { 
       $(this).attr('title', $("this").data('title')); 
      } 
     ); 
    } 
})(jQuery); 

//call the plugin 
$(function(){ 
$('.wrapper ul li a').showText(); 

}); 

我得到了代码从别的地方上的计算器,但我似乎无法得到它的工作,并帮助将大大appriciated。

+0

请定义*只是似乎无法得到它的工作*。你有什么错误吗?我没有看到从链接中删除title属性的任何理由。你为什么这样做? – 2010-06-02 09:35:29

回答

0

我不知道的东西data,为什么你想从元素删除title属性(我认为没有理由做它),但你可能想要:

(function($) { 
    $.fn.showText = function() { 
     this.each(function() { 
      $(this).hover(
       function() {   
        $(".itemDecription p").text($(this).attr('title')); 
        $(this).data('title', $(this).attr('title')).removeAttr('title'); 
       }, 
       function() { 
        $(".itemDecription p").empty(); 
        $(this).attr('title', $(this).data('title')); 
       } 
      ); 
     }); 
     return this; 
    } 
})(jQuery); 

重要的是,哟你使用each(),因为选择器可能会选择多个a元素(也许这是它不起作用的原因)。

所以也How to develop a jQuery plugin

0
.appendTo("itemDecription p"); // error here... it's either '.itemDecription p' or '#itemDecription p' 

编辑

I modified your codes...敬请期待...

+0

感谢您的快速回复,我纠正了我的错误,但它仍然无法正常工作。 – ivordesign 2010-06-02 09:41:09

+0

从我可以看到的是,它没有取代文字回到标题attr悬停后 – ivordesign 2010-06-02 09:45:31

+0

请参阅编辑... – Reigel 2010-06-02 09:53:26

相关问题