首页 > 其他分享 >Html DOM操作TABLE

Html DOM操作TABLE

时间:2024-07-14 09:08:54浏览次数:18  
标签:20 name DOM 18 age sex Html 李四 TABLE

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>DOM操作TABLE</title>
		<style type="text/css">
			.table-container{
			
				}
			
				caption{
					padding: 10px;
					font-size: 30px;
					font-weight: bold;
				}
			
				table{
					border-collapse: collapse;
					width: 80%;
					margin: 0px auto;
					border: 1px solid #ddd;
				}
			
				th, td{
					padding: 10px 10px;
					text-align: center;
				}
			    /* th固定在窗口顶部 */
				th{
					position: -webkit-sticky;
					position: sticky;
					top: 0;                     
					background-color: #03A9F4;
					color: #FFF;
					border: 1px solid #ddd;
				}
			
				table tr:nth-child(odd){
					background-color: #F2F2F2; /* 奇数行背景颜色 */
				}
				table tr:nth-child(even){
					background-color: #F9F9F9; /* 奇数行背景颜色 */
				}
		</style>
		<script src="https://config.net.cn/tools/static/Main/jquery.min.js"></script>
		<script type="text/javascript">
			var stu = [
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "王五", "sex": "男", "age": "19" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "王五", "sex": "男", "age": "19" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "王五", "sex": "男", "age": "19" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "王五", "sex": "男", "age": "19" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "王五", "sex": "男", "age": "19" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "王五", "sex": "男", "age": "19" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "王五", "sex": "男", "age": "19" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "张三", "sex": "男", "age": "20" },
				{ "name": "李四", "sex": "男", "age": "18" },
				{ "name": "王五", "sex": "男", "age": "19" },
			  ];
					/**
					*
					1.Js直接解析JSON; 
					2.AJAX去获取JSON(不跨域); 
					3.PHP中用cURL函数去获取JSON(任何URL) 
					*
					**/
			  $(document).ready(function() {
				var s = "";
				for(var i = 0; i < stu.length; i++) {
					id = i+1;
					tr = "<tr>";
					td = "<td>" + id + "</td><td>" + stu[i].name + "</td><td>" + stu[i].sex + "</td><td>" +
					stu[i].age + "</td></tr>";
					$("#tab").append(tr + td);
				}
			  });
		</script>
	</head>
	<body>
		<div class="table-container">
			<table id="tab" border="1" cellspacing="0">
				<caption id="caption">caption<span id="p2" style="font-size: 16px;"> 自动刷新!<a href="?id=1">caption</a>
					</span>
				</caption>
				<thead>
					<tr>
						<th>ID</th>
						<th>name</th>
						<th>sex</th>
						<th>age</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>文字描述</td>
						<td>文字描述</td>
						<td>文字描述</td>
						<td>文字描述</td>
					</tr>
				</tbody>
				<tfoot id="tfoot">
					<tr style="background: #785d35;color: #FFF;">
						<td>合计</td>
						<td></td>
						<td></td>
						<td></td>
					</tr>
				</tfoot>
			</table>
		</div>
	</body>
</html>

  

标签:20,name,DOM,18,age,sex,Html,李四,TABLE
From: https://www.cnblogs.com/zhouein/p/18301097

相关文章

  • Hypertable install of rhel6.0
    1.rpm 安装:(如果已存在,会提示冲突,使用--replacefiles)1.1 编译环境安装gccgcc-c++makecmake(在adminmachine上,放置rpm包的文件里依次执行下面的语句):  sudorpm-ivhcpp-4.4.6-4.el6.x86_64.rpm--replacefiles sudorpm-ivhlibgcc-4.4.6-4.el6.x86_64.rpm--......
  • HTML 语言代码
    ISO语言代码HTML的lang属性可用于网页或部分网页的语言。这对搜索引擎和浏览器是有帮助的。根据W3C推荐标准,您应该通过 <html> 标签中的 lang 属性对每张页面中的主要语言进行声明,比如:<htmllang="en">...</html>在XHTML中,采用如下方式在<html>标签中对语......
  • 【网页前端设计HTML】水平线、div、自闭合标签及块元素和行内元素、特殊符号
    使用所分享的知识,还不能够完成下图的设计,观察一下,我们还有什么知识没讲呢?聪明的你一定能看到:一条长长的线分隔开每一个科目,但是这条长线怎么表示,用什么标签呢?一、水平线标签我来告诉你,这条长长的线,我们称之为“水平线”。在HTML中,我们可以使用“hr标签”来实现一条水......
  • 前端HTML+CSS实现3D炫酷相册(附源码)
    前言    利用基础的html和css实现3D相册(可自我添加照片)    本人初衷是为了验证所学的知识,顺便想逗女朋友开心......
  • Html5前端基本知识整理与回顾上篇
    今天我们结合之前上传的知识资源来回顾学习的Html5前端知识,与大家共勉,一起学习。目录介绍了解注释标签结构排版标签标题标签​编辑段落标签​编辑换⾏标签​编辑⽔平分割线⽂本格式化标签媒体标签绝对路径相对路径音频标签格式​编辑注意点视频标签格......
  • WEB前端02-HTML5基础(02)
    7.表格标签在基本表格结构中,表格标题、项目表头和数据资料构成了表格基本结构三个要素。table标签:定义表格整体<caption>我的标题</caption>:表格的标题tr标签:定义表格的行height:设置行的高度align:设置行内容的水平对齐方式valign:设置行内容的垂直对齐方式:topmiddl......
  • 10-Hashtable底层结构和源码分析
    10-Hashtable底层结构和源码分析介绍汇总:Hashtable的基本介绍Hashtable底层机制说明Hashtable和HashMap对比1-Hashtable的基本介绍存放的元素是键值对:即K-VHashtable的键和值都不能为null,不然后抛出NullPointerException异常Hashtable使用方法基本上和Hash......
  • Web开发 —— 放大镜效果(HTML、CSS、JavaScript)
    目录一、需求描述二、实现效果三、完整代码四、实现过程1、HTML页面结构2、CSS元素样式3、JavaScript动态控制(1)获取元素(2)控制大图和遮罩层的显隐性(3)遮罩层跟随鼠标移动(4)控制遮罩层移动范围(5)显示放大图一、需求描述前端实现放大镜效果;鼠标移入图片区域,显示遮......
  • HTML(3)
    10.列表定义:布局内容排列整齐的区域。分类:无序列表,有序列表,定义列表1.无序列表:ul是无序列表,li是列表条目,ul嵌套li<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,......
  • JS组件系列——BootstrapTable 行内编辑解决方案:x-editable
    转载:http://www.cnblogs.com/landeanfen/p/5821192.html#_label2  阅读目录一、x-editable组件介绍二、bootstrapTable行内编辑初始方案三、bootstrapTable行内编辑最终方案1、文本框2、时间选择框3、下拉框4、复选框5、“阴魂不散”的select2四、总结 正......