Checkbox Check Event Listener

前端 未结 3 1983
深忆病人
深忆病人 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:25

    Since I don't see the jQuery tag in the OP, here is a javascript only option :

    document.addEventListener("DOMContentLoaded", function (event) {
        var _selector = document.querySelector('input[name=myCheckbox]');
        _selector.addEventListener('change', function (event) {
            if (_selector.checked) {
                // do something if checked
            } else {
                // do something else otherwise
            }
        });
    });
    

    See JSFIDDLE

提交回复
热议问题