How to add a onclick event to an element using javascript

前端 未结 7 1116
忘掉有多难
忘掉有多难 2020-12-04 02:03

I have created an element using document.getElementsByClassname, and would like to add a onclick event to this element, so that when someone clicks on this element onclick f

7条回答
  •  抹茶落季
    2020-12-04 02:30

    Please try the following:
    
    var rows = 3;
    var cols = 3;
    var defaultVal=0;
    var mainDiv=document.getElementById("mainDiv")
    var arr = []
    for (var i = 0; i < rows; i++) {
        arr[i] = [];
      for(var j=0;j

提交回复
热议问题