原生JS 监听单选框值得变化

  <div id="block">
    <input type="radio" name="a" value="1">1
    <input type="radio" name="a" value="2">2
    <input type="radio" name="a" value="3">3
  </div>

  

    document.getElementById("block").addEventListener("click",function(e){
      if(e.target.tagName=="INPUT"){
        console.log("radiovalue",e.target.value)
      }
    })

  

posted @ 2020-07-06 09:33  伴月阁  阅读(4063)  评论(0编辑  收藏  举报