JQuery Mobile trigger('create') command not working

后端 未结 10 1920
清歌不尽
清歌不尽 2020-12-06 10:11

JQuery Mobile is making my cry tonight. I\'m trying to build custom controls so I don\'t repeat certain elements through my app, and it\'s giving me a hard time. Specifica

10条回答
  •  暖寄归人
    2020-12-06 10:41

    this question is old enough by now, but I just ran into the problem so here is how I handled it -- (this maintains the set data-theme and applies the correct roles for the containing divs and headers)

    $('your_selector').find('div[data-role="header"], div[data-role="footer"]').each(
        function( ){
            var dR = $(this).attr('data-role');
            var dT = $(this).attr('data-theme');
            $(this).addClass('ui-' + dR + ' ui-bar-' + dT).attr('role', (dR == 'header' ? 'banner' : 'contentinfo') ).children('h1, h2, h3, h4').each(
                function( ){
                    $(this).addClass('ui-title').attr({'role':'heading', 'aria-level':'1'});
                }
            )
        }
    );
    

    depending on your code, it might be more convenient to set this up as a function and send your selector as an argument. Hope it helps.

提交回复
热议问题