2014-02-06 118 views
0

我試圖更改自定義屬性,並沒有運氣。我錯過了一些愚蠢的東西嗎?jquery更改自定義屬性狀態

HTML:

<div class="favorite" status="off">&#9734</div> 

JQuery的:

$(".favorite").click(
     function(){ 
      var currentvalue = $(this).attr("status"); 
      if(currentvalue == "off"){ 
       $(this).html("&#9733;"); 
       $(this).attr("status") = "on"; 
      }else if (currentvalue == "on"){ 
       $(this).html("&#9734;"); 
       $(this).attr("status") = "off"; 
      } 
     } 
    ); 

我的明星改爲填寫,但地位永遠不會改變爲 「on」。我錯過了什麼?

謝謝!

回答

6

您需要使用setter版本.attr()(將值設置爲第二個參數)。

$(this).attr("status", 'on')