简体   繁体   中英

Jquery mobile toggle button data-theme on button press

I have a buttons of a certain class

<div class="prog-day">
    <div class="prog-clear" data-role="controlgroup" data-type="horizontal">
        <a href="#" data-role="button" data-mini="true" data-theme="b">Clear</a>
    </div>  
    <p></p>
</div    

and I want to toggle the theme color onclick. The toggle ID changes and does the data-theme letter but the color doesn't change. This is all the things (trigger,create, refresh) I've tried based upon other posts

$(".prog-day a").click(function() {
    console.log("clicked a day button");
    progToggle = $(this).attr("progToggle");
    if ( progToggle == "1"  ) {
        $(this).attr("data-theme","b").refresh;
        $(this).attr("progToggle","0");
        $(this).trigger('create');
        $(this).trigger('refresh');
        $('.prog-day p').html($(this).attr("progToggle")+$(this).attr("data-theme"));
        progToggle = $(this).attr("progToggle");
     }
     else {
        $(this).attr("data-theme","d").refresh;
        $(this).attr("progToggle","1");
        $(this).trigger('create');
        $(this).trigger('refresh');
        $('.prog-day p').html($(this).attr("progToggle")+$(this).attr("data-theme"));
        progToggle = $(this).attr("progToggle");
    }           
});

What am I missing here. Am I better off skipping this JQM stying stuff and just do it myself? I'd actually like the buttons to toggle on the down press, not the release. Perhaps you could fiddle with http://jsfiddle.net/PLx8v/3/

如果要检查是否相等,请确保您的if语句具有3个相等的符号

if( progToggle === '1' ) {}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM