Get value if checkbox checked

后端 未结 6 1446
情歌与酒
情歌与酒 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 check ckeckbox status:

    $("#getusb").on("change", function() {
      //check if is checked
      if (this.checked) {
        //set the span text according to checkbox value
        $('.active-usb').text(this.value);
      } else {
        //if is not checked hide span
        $(".active-usb").hide();
      }
    });
    
    
    

提交回复
热议问题