How set item checkbox when i click on element span which have this checkbox?

前端 未结 3 1302
抹茶落季
抹茶落季 2021-01-21 05:11

Me need set item checkbox when i click on element span which have this checkbox.

Code:



        
3条回答
  •  执笔经年
    2021-01-21 05:26

    First of all, do you want a checkbox or a radio input? Your code is a radio input.

    Here is a jsfiddle showing what you require

    You need the following javascript:

    $('span').click(
        function() {
            var cb = $(this).find(":radio")[0];
    
            if (!$(cb).attr("checked")) {
                $(cb).attr("checked", "checked");
            } else {
                $(cb).removeAttr("checked");
            }
        }
    );
    
    $('span input').click(
        function(event){
            event.stopPropagation();
    });​
    

提交回复
热议问题