Jquery Use Image As CheckBox

前端 未结 6 1105
情话喂你
情话喂你 2021-01-07 08:59

I am in pursuit of implementing images as checkboxes. For now I am trying out a sample. The code below contains a simple image with a submit button next to it. On clicking t

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-07 09:28

    Here is the solution of your question. I hope this will help you.

    CSS

    .checked {border:solid 2px red}
    

    HTML Code

    jQuery Code

    $(document).ready(function() {
    
        $('#blr').on('click', function(){
            var $$ = $(this)
            if( !$$.is('.checked')){
                $$.addClass('checked');
                $('#imgCheck').prop('checked', true);
            } else {
                $$.removeClass('checked');
                $('#imgCheck').prop('checked', false);
            }
        })
    
    });
    

    Working Example : Demo

提交回复
热议问题