2012-11-13 95 views
0

我創建了一個風格改變背景顏色按鈕上飛jQuery Mobile的

.someRedStuff 
{ 
background:red !important; 
} 

我想星形圖標的顏色變爲紅色按鈕被點擊時

<a data-role="button" data-iconpos= "notext" data-icon="star" id="custom-li-3" onclick="changeColor()"></a> 

我想這個代碼,但它似乎並沒有做的伎倆..

function changeColor() 
     {   
      $('#custom - li - 3').removeClass('ui-icon-star').addClass('someRedStuff'); 
     } 

如何改變S的顏色點擊焦油圖標?

+0

jQuery Mobile的最有可能修改標籤(添加額外的HTML)在運行時。 – Coby

回答

2

你的元素選擇器有空格。 刪除選擇器中的空格以匹配爲元素聲明的ID。

$('#custom-li-3').removeClass('ui-icon-star').addClass('someRedStuff'); 
0

這是否工作:

JS

$('#custom-li-3').on('click', function(event){ 
    $(this).toggleClass('someRedStuff'); 
}); 

HTML

<div data-role="page" class="type-home"> 

    <div data-role="content"> 
     <a data-role="button" data-iconpos= "notext" data-icon="star" id="custom-li-3"></a> 
    </div> 
</div>​ 

CSS

.someRedStuff 
{ 
background:red !important; 
}