How do I add a simple onClick event handler to a canvas element?

前端 未结 7 1877
自闭症患者
自闭症患者 2020-11-22 09:07

I\'m an experienced Java programmer but am looking at some JavaScript/HTML5 stuff for the first time in about a decade. I\'m completely stumped on what should be the simple

7条回答
  •  甜味超标
    2020-11-22 09:33

    Probably very late to the answer but I just read this while preparing for my 70-480 exam, and found this to work -

    var elem = document.getElementById('myCanvas');
    elem.onclick = function() { alert("hello world"); }
    

    Notice the event as onclick instead of onClick.

    JS Bin example.

提交回复
热议问题