Get value if checkbox checked

后端 未结 6 1374
情歌与酒
情歌与酒 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:20

    You can use the checked property to determine if the checkbox is checked or not. Then you can get the value of the checkbox that raised the event using this. Try this:

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

提交回复
热议问题