toggle checkbox with javascript

前端 未结 4 1880
南旧
南旧 2021-01-27 06:28

I want to uncheck a checkbox using javascript. I have one button which just unchecks the box and works fine:

function clear() {
document.getElementById(\"check\"         


        
4条回答
  •  长发绾君心
    2021-01-27 06:52

    You need a boolean to do that.

    Take a look at this pen:

    https://codepen.io/anon/pen/jJyXgO

    let checkbox = document.querySelectorAll('#check')[0]
    
    setInterval(function() {
      checkbox.checked = !checkbox.checked
    }, 1000)
    

提交回复
热议问题