Get value if checkbox checked

后端 未结 6 1457
情歌与酒
情歌与酒 2021-01-23 14:21

I\'m using a jQuery function to get the value of an checked checkbox.

How to hide the value in the span class \"active-usb\" if the checkbox is not checked anymore?

6条回答
  •  情深已故
    2021-01-23 15:17

    You can try something like this :-

    $("#getusb").change(function(){
       if($(this).is(':checked')){
         $('.active-usb').text($(this).val());
       }  
       else{
         $('.active-usb').text('');
       }
    }).change();
    

    OR

    $("#getusb").change(function(){
       $('.active-usb').text($(this).is(':checked') ? $(this).val() : ''); 
    }).change();
    

提交回复
热议问题