Attaching event handler to DOM elements

前端 未结 6 711
[愿得一人]
[愿得一人] 2021-01-28 12:30

I am working on a tic tac toe game, which is almost complete. The only thing I am left wondering about is if it is possible to add an event handler for onclick fro

6条回答
  •  梦如初夏
    2021-01-28 13:03

    Use this:

    document.getElementById('element_id').onclick = function(){ playerMove(this); };
    

    For each Div, change 'element_id' with 'one', 'two', ...

提交回复
热议问题