【问题标题】:Remove data-icon dynamically动态删除数据图标
【发布时间】:2013-10-24 10:47:16
【问题描述】:

我正在用 JavaScript 和 jQuery 开发一个应用程序。在应用程序中,有一个 listview (jQuery mobile) 和一些项目。

我已经创建了一个函数来动态删除 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');
});

我做错了什么?

【问题讨论】:

    标签: javascript jquery mobile jquery-mobile-listview


    【解决方案1】:

    要删除一个属性,像这样使用 .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');
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多