2011-03-24 15 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"); 
     }); 

希望這個作品^^