Onsen 2.0 - Adding event listener to Ons-Switch with Javascript
问题 I fear I am missing something really simple, but I have tried multiple attempts with various errors. On to the code: <script> document.getElementById("optStats").on("change", function(e) { alert("Switch changed!"); }); </script> <ons-switch modifier="list-item" id="optStats"></ons-switch> So the above does not work. It generates an error of Uncaught TypeError: Cannot read property of on of null . So I assumed that I needed to add the function to the onload init function but it still failed