2011-03-24 39 views
0

我是新的jQuery,以及与此JQuery的:链接的标题属性不变

$("#trigger").click(
    function(){ 
     $("#pnel-menu").toggle("slow"); 
     $(this).toggleClass("active"); 
     $(this).attr("title", "Open Panel"); 
    }, function() { 
      $(this).attr("title", "Close Panel"); 
      return false; 
}); 

HTML有问题

<div id="pnel-menu"> 
    menu 
</div> 
<p class="slidebar"> 
    <a id="trigger" title="" href="#"></a> 
</p> 
<div id="pnel-cont"> 
    Lorem ipsum dolor sit amet, consectetur adipiscing elit 
</div> 

我喜欢做的是dinamically时更改.trigger标题它会克服打开或关闭#pnel菜单。

但它不会改变?没有任何人可以提供一些线索,由于之前:)

回答

2

试试这个:

$("#trigger").click(function(){ 
    var that = $(this); 
    $("#pnel-menu").toggle("slow"); 
    that.toggleClass("active"); 
    that.attr("title", (that.hasClass("active")?"Close":"Open") + " Panel"); 
}); 
1

我不认为你应该使用两个函数与,作为分隔符

$("#trigger").click(function(){ 
     $("#pnel-menu").toggle("slow"); 
     $(this).toggleClass("active"); 
     if($(this).attr("title") == "Open Panel"){ 
       $(this).attr("title", "Close Panel");  
       return false; 
     } 
     else 
       $(this).attr("title", "Open Panel"); 
     }); 

希望这个作品^^