Checkbox Check Event Listener

前端 未结 3 1981
深忆病人
深忆病人 2020-11-28 03:58

Recently I have been working with the Chrome Plugin API and I am looking to develop a plugin which will make life easier for me for managing a website.

Now what I wi

3条回答
  •  星月不相逢
    2020-11-28 04:31

    If you have a checkbox in your html something like:

    and you want to add an EventListener to this checkbox using javascript, in your associated js file, you can do as follows:

    checkbox = document.getElementById('conducted');
    
    checkbox.addEventListener('change', e => {
    
        if(e.target.checked){
            //do something
        }
    
    });
    

提交回复
热议问题