小编sri*_*h_k的帖子

如何在此代码中将click事件添加到表格单元格?

在此代码中,我想使用javascript使表格单元格可单击.

还请告诉我如何使用click事件使用i,j值.

<!DOCTYPE html>
<html>
<head>
<style>
 td 
 {
   height : 30px;
   width : 30px;
   cursor: pointer;
 }
</style>

<script>
function clickHere(){
var table = document.getElementById("myTable");
var row ;
var cell;
for(var i=0;i<2;i++){
  row = table.insertRow(i);
  for(var j=0;j<2;j++){
    cell = row.insertCell(j);
  }
 }
}
</script>
</head>

<body onload="clickHere()">
 <table id = "myTable" border="1"></table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

javascript

4
推荐指数
1
解决办法
9786
查看次数

标签 统计

javascript ×1