2013-02-23 55 views
0

我試圖在div淡入時更改background-color,但下面的代碼無法使用。當div淡入時更改背景顏色

相反,它只fadeOut並沒有任何顯示,當我試圖clickfadeIn.

$('#divbutton').toggle(function(){ 
     $('#divbutton').text('Show'); 
     $('#message').fadeOut('1000'); 

    } , 
    function(){ 
     $('#divbutton').text('Hide'); 
     $('#message').$this.css('background-color', 'red').fadeIn('1000'); 

    } 
); 
+4

你想用'$('#message')。$ this'實現什麼? – undefined 2013-02-23 04:04:37

+0

請正確縮進您的代碼 – martriay 2013-02-23 04:04:40

+0

可能要刪除'$ this'。 '$(this)'會引用我相信的'#divbutton'。你沒有得到控制檯中的語法錯誤?你一定是。/ – Leeish 2013-02-23 04:07:40

回答

0

你的語法下面的行不正確。更改:

$('#message')。$ this.css('background-color','red')。fadeIn('1000');

到:

$( '#消息'),CSS( '背景顏色', '紅')淡入( '1000');