JS 如何获取radio或者checkbox选中后的值

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<script> 

    function inputChecked() {
      var inputSelect = document.getElementsByTagName('input');
      var obj = {
          radio: [],
          checkbox: []
        },
        value = '';
      for (var i = 0, len = inputSelect.length; i < len; i++) {
        if (inputSelect[i].checked && inputSelect[i].type === 'radio') {
          obj.radio.push(inputSelect[i].value);
          value += '单选框:' + inputSelect[i].value + '\n';
        }
        if (inputSelect[i].checked && inputSelect[i].type === 'checkbox') {
          obj.checkbox.push(inputSelect[i].value);
          value += '多选框:' + inputSelect[i].value + '\n';
        }
      }
      alert(value);
      return obj;
    }
 
</script>
</head>
<body>

 <input type="radio" name="sex" value="man" id="man" checked οnclick="inputChecked()">
  <label for="man">男</label>
  <input type="radio" name="sex" value="female" id="female" οnclick="inputChecked()">
  <label for="female">女</label>
  <p>多选框</p>
  <input type="checkbox" name="fruits" value="apple" id="apple" checked οnclick="inputChecked()">
  <label for="apple">苹果</label>
  <input type="checkbox" name="fruits" value="orange" id="orange" οnclick="inputChecked()">
  <label for="orange">橙子</label>

<button type="button" οnclick="inputChecked()">显示</button>

</body>
</html>

JS 如何获取radio或者checkbox选中后的值