第一种:前段常规绑定:
<button type="button" class="recolor" onclick="reCol(‘rowIndex‘,‘colIndex‘)">重新着色</button>
第2种:js绑定监听事件:
//添加监听器 table.addEventListener("click", display, false); } (generat()); //获取鼠标点击的行和列 function display(event) { var colIndex = null; var rowIndex = null; var element = event.srcElement || event.target; if (!element) return; if (element.tagName != "TD") return; colIndex = element.cellIndex; rowIndex = element.parentNode.rowIndex; console.log("row:" + rowIndex + ", col:" + colIndex); return rowIndex, colIndex;}
第2种:js+“”on“”绑定事件:
document.onmouseup = function (event) { console.log(event.target + onmouseup); tartgetTd = null; coltargetTd = null; resizeable = false; mousedown = false; colmousedown = false; colresizeable = false; document.body.style.cursor = ‘default‘; }
时间: 2024-10-11 00:12:34