表格对象的获取

	                        var oT = document.getElementById("tb");
				
				//获取head
				console.log(oT.tHead);
				console.log(typeof oT.tHead);
				
				//获取body
				console.log(oT.tBodies);//[tbody]
				console.log(typeof oT.tBodies);
				
				//获取foot
				console.log(oT.tFoot);
				
				//获取行[tr,tr...]
				console.log(oT.rows);
				//修改第三行的颜色
				oT.rows[2].style.background="blue";
				
				//获取单元格(不能直接通过表格对象获取,通过行获取单元格)
//				console.log(oT.cells);//undefined

				var rows = oT.rows;//[tr,tr...]
				
				var cells=rows[rows.length-1].cells;
				console.log(cells);//[td,td,td,td]
				
				cells[cells.length-1].style.background="red";
				

   表格元素的修改

                                var oT = document.getElementById("tb");
				
				//插入行
				//参数:下标
				var newRow=oT.insertRow(1);
//				console.log(newRow);
//				newRow.innerHTML="new insertRow";
				
				//在行中插入单元格
				var newTd=newRow.insertCell(0);
				newTd.innerHTML = "小明";
				
//				console.log(newTd);

				newRow.insertCell(1).innerHTML="18";
				newRow.insertCell(2).innerHTML="男";
				newRow.insertCell(3).innerHTML="工程师";        

  

相关文章:

  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
  • 2021-10-25
  • 2021-03-30
猜你喜欢
  • 2022-12-23
  • 2021-11-24
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
相关资源
相似解决方案