2013-10-24 58 views
0

我正在開發一個JavaScript和jQuery應用程序。在應用程序中,有一些listview(jQuery手機)和一些項目。動態刪除數據圖標

我已經做了功能動態消除在listview項的所有數據圖標,但它不工作:

$(".lvItem").each(function() { 
    $(this).attr('data-icon', 'false'); 
    $(this).find('.ui-icon').removeClass('ui-icon-' + 'arrow-r'); 
}); 

但是,如果我嘗試動態地更改圖標,它完美:

$(".lvItem").each(function() { 
    $(this).attr('data-icon', 'arrow-u'); 
    $(this).find('.ui-icon').addClass('ui-icon-' + 'arrow-u'); 
    $(this).find('.ui-icon').removeClass('ui-icon-' + 'arrow-r'); 
}); 

我在做什麼錯?

回答

0

要刪除一個屬性使用.removeAttr()像這樣

$(".lvItem").each(function() { 
    $(this).removeAttr('data-icon'); 
    //remember that you can access data- attributes with the data function 
    //like this   
    //modify a value 
    $(this).data('icon','value-1'); 
    //read a value 
    icon = $(this).data('icon'); 
});