combine checkbox with jquery mobile listview

后端 未结 3 1011
孤独总比滥情好
孤独总比滥情好 2020-12-21 15:07

I\'d like to use a jqm styled checkbox in my listview cells. I\'ve made a composite picture to show the desired end result:

http://tinyurl.com/ctvko27

Whenev

相关标签:
3条回答
  • 2020-12-21 15:22

    Solution

    Here's a solution for you, I had a spare time so here it is: http://jsfiddle.net/Gajotres/ek2QT/

    Javascript code:

    First on pagebeforeshow select/unselect our custom checkboxes.

    $('#index').live('pagebeforeshow',function(e,data){
        $('input[type="checkbox"]').each(function(){
            ($(this).is(':checked')) ? $(this).parent().parent().addClass('checked') : $(this).parent().parent().addClass('not-checked');   
        });
    });
    

    This part will handle checkbox changing states.

    $('.checkBoxLeft').bind('click', function(e) {
        if($(this).find('input[type="checkbox"]').is(':checked')){
            $(this).removeClass('checked').addClass('not-checked');
            $(this).find('input[type="checkbox"]').attr('checked' , false);
        } else {
            $(this).removeClass('not-checked').addClass('checked');             
            $(this).find('input[type="checkbox"]').attr('checked' , true);
        }
    });
    

    Rest off the css is in the example, img used for custom states can be found here:

    Final notes

    If you want to find more about how to customize jQuery Mobile page and widgets then take a look at this article. It comes with a lot of working examples, including why is !important necessary for jQuery Mobile.

    0 讨论(0)
  • 2020-12-21 15:29

    There are a couple of approaches that might work. You might try placing the checkbox head of the hyperlink <a /> tag. You might also disable the automatic enhancement on your checkbox. Fundamentally you are going to have issues with touch events and any overlap of the two controls.

    <input type="checkbox" data-role="none" />
    
    0 讨论(0)
  • 2020-12-21 15:35

    Just tried to use Gajotre's solution with the latest versions of jquery (1.9.1) + jquerymobile (1.3.2) but unfortunately it didn't work.

    You have to change the

    $(this).find('input[type="checkbox"]').attr('checked' , false);
    $(this).find('input[type="checkbox"]').attr('checked' , true);
    

    to

    $(this).find('input[type="checkbox"]').prop('checked' , false);
    $(this).find('input[type="checkbox"]').prop('checked' , true);
    

    otherwise you'll be able to change the checkbox "checked" value only once.

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