Change data-icon on click with jquery mobile

前端 未结 4 1147
独厮守ぢ
独厮守ぢ 2021-01-18 12:58

This is my code:

function togglePOIAndDisplay(toggle){
    var display = $(toggle).attr(\'data-icon\');
    console.log(display);
    if(display == \'minus\'         


        
相关标签:
4条回答
  • 2021-01-18 13:39

    For listviews, you need to insert a span.

    $("#times").off('click','li').on("click","li",function() {
    
     /* add a checkbox when you click the listview li  */
     $(this).find('div.ui-li').append('<span class="ui-icon ui-icon-check ui-icon-shadow">&nbsp;</span>');
    
    });
    
    0 讨论(0)
  • 2021-01-18 13:43

    http://jsfiddle.net/phillpafford/8pwFK/29/

    change custom icon to star icon.

    $(this).attr('data-icon','star');
    $(this).find('.ui-icon').removeClass('ui-icon-custom').addClass('ui-icon-star');
    

    this example is easy to study.

    0 讨论(0)
  • 2021-01-18 13:45

    This depends on whether it's a button, or a select, or some other thing that accepts the data-icon attribute. Unfortunately, jQuery Mobile doesn't have great support for dynamically changing things controlled by data-* attributes, so you'll have to adjust the attribute as well as modify the classes on the child elements.

    For buttons, something like this ought to work:

    $(buttonSelector).attr('data-icon', newIcon);
                     .find('.ui-icon')
                         .addClass('ui-icon-' + newIcon)
                         .removeClass('ui-icon-' + oldIcon);
    
    0 讨论(0)
  • 2021-01-18 13:48

    If the icon is inside a button like this:

    <a id="buttonID" href="#" data-role="button" data-icon="delete">Button</a>
    

    You can change the icon with the buttonMarkup function:

    $('#buttonID').buttonMarkup({ icon: "check" });
    

    Or to your custom icon:

    $('#buttonID').buttonMarkup({ icon: "my-icon" });
    

    Example: http://jsfiddle.net/u8fnJ/1/

    As shown in this post How to refresh a button in a header with jQueryMobile?

    0 讨论(0)
提交回复
热议问题