javascript 操作table的特性
作者:bea
<html xmlns="http://www.w3.org/1999/xhtml" > <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/> <title>javascript操作table的特性</title> <script type="text/javascript"><!-- functi
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
<title>javascript操作table的特性</title>
<script type="text/javascript"><!--
function f(){
//创建一个表格
var oTable = document.createElement("table");
oTable.setAttribute("border","1");
oTable.setAttribute("width","300px");
//
var oTBody = document.createElement("tbody");
oTable.appendChild(oTBody);
//创建第一行
oTBody.insertRow(0);
oTBody.rows[0].insertCell(0);
oTBody.rows[0].cells[0].appendChild(document.createTextNode("Cell 1,1"));
oTBody.rows[0].insertCell(1);
oTBody.rows[0].cells[1].appendChild(document.createTextNode("Cell 2,1"));
//创建第二行
oTBody.insertRow(1);
oTBody.rows[1].insertCell(0);
oTBody.rows[1].cells[0].appendChild(document.createTextNode("Cell 1,2"));
oTBody.rows[1].insertCell(1);
oTBody.rows[1].cells[1].appendChild(document.createTextNode("Cell 2,2"));
//
document.body.appendChild(oTable);
}
// --></script>
</head>
<body onclick="f();">
<div>hello</div>
<table border="1" width="300px">
<tbody>
<tr>
<td>Cell 1,1</td>
<td>Cell 2,1</td>
</tr>
<tr>
<td>Cell 1,2</td>
<td>Cell 2,2</td>
</tr>
</tbody>
</table>
</body>
</html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]
可以直接点击页面的任何部分即可看到效果。
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- 用 Javascript 验证表单(form)中多选框(checkbox)值
- Javascript String.replace的妙用
- Javascript 检测、添加、移除样式(className)函数代码
- Javascript 阻止浏览器默认操作的实现代码
- javascript 流畅动画实现原理
- javascript 定义初始化数组函数
- JS 网页彩蛋 实现代码
- javascript十个最常用的自定义函数(中文版)
- javascript 获取select下拉列表值的代码
- Javascript中的var_dump函数实现代码
- jquery tools系列 expose 学习
- jquery tools系列 overlay 学习
- jquery tools 系列 scrollable(2)
- jquery tools 系列 scrollable学习
- javascript事件问题
- js跨域和ajax 跨域问题的实现思路
- JavaScript 密码强度判断代码
- 关于javascript中的parseInt使用技巧
- jquery判断单个复选框是否被选中的代码