关于HTML的Element
今天搞HTML的时候,发现了一些操作element的方法。先引用一篇。
1.document.getElementById(id);
2.document.getElementByTagName(tagName);
3.element.childNodes
--element.firstChild=element.childNodes[0];
--element.lastChild=element.childNodes[element.childNonts.length-1];
4.element.parentNode
5.element.nextSibling; //引用下一个兄弟结点
element.previousSibling; //引用上一个兄弟结点
6.nodeName属性获得结点名称
--对于元素结点返回的是标记名称,如:<a herf><a>返回的是"a"
--对于属性结点返回的是属性名称,如:class="test" 返回的是test
--对于文本结点返回的是文本的内容
7.nodeType返回结点的类型
--元素结点返回1
--属性结点返回2
--文本结点返回3
8.nodeValue返回结点的值
--元素结点返回null
--属性结点返回undefined
--文本结点返回文本内容
9.hasChildNodes()
10.tagName
11.每个属性结点都是元素结点的一个属性,可以通过(元素结点.属性名称)访问
12 setAttribute()
--elementNode.setAttribute(attributeName,attributeValue);
13.使用getAttribute()方法
--elementNode.getAttribute(attributeName);
14.innerHTML和innerText属性
<script language"javaScript" type="text/javascript">
function cleanWhitespace(element)
{
for(var i=0; i<element.childNotes.length; i++)
{
var node = element.childNodes[i];
if(node.nodeType == 3 && !/\S/.test(node.nodeValue))
{
node.parentNode.removeChild(node);
}
}
}
</script>
15.document.createElement()方法创建元素结点
--如:document.createElement("Span");
16.document.createTextNode()方法创建文本结点
--如:document.createTextNode(" ");
17.使用appendChild()方法添加结点
18.使用insertBefore()方法插入子节点
19.使用replaceChild方法取代子结点
20.使用cloneNode方法复制结点
--node.cloneNode(includeChildren);
--includeChildren为bool,表示是否复制其子结点
21.使用removeChild方法删除子结点
22.添加行和单元格
var _table=document.createElement("table"); //创建表
table.insertRow(i); //在table的第i行插入行
row.insertCell(i); //在row的第i个位置插入单元格
23.引用单元格对象
- -table.rows[i].cells[i];
24.删除行和单元格
--table.deleteRow(index);
--row.deleteCell(index);
25.交换两行获得两个单元格的位置
node1.swapNode(node2);
然后再讲自己的验证,搬来代码如下,以下内容运行于IE9,Chrome均可:
<script type="text/javascript">
function displayKeisaiMeisai(img){
var tr = img.parentNode.parentNode;
var tr1 = tr.getElementsByTagName("TD")[1].getElementsByTagName("TABLE")[0].getElementsByTagName("TR")[1];
if(tr1.style.display=="none"){
tr1.style.display="block";
img.src = "./img/triangle_displayNone.png";
} else {
tr1.style.display="none";
img.src = "./img/triangle_dispaly.png";
}
} function addRow2() {
var _tab = document.getElementById("keisai_b");
var newnode = _tab.getElementsByTagName("TR")[0].cloneNode(true);
_tab.getElementsByTagName("TBODY")[0].appendChild(newnode);
} </script> <input type="button" value="Test追加挿入"
style="height: 35px; width: 150px; margin-top: 3px; margin-left: 0px;"
id="btnAdd"
onClick="addRow2();" />
<table id = "keisai_b">
<tr>
<td>
<table name="keisai_b_node">
<tr>
<td style="vertical-align:top;">
<img id="keisai_b_1" style="margin-top: 5px;" src="./img/triangle_dispaly.png" onclick="displayKeisaiMeisai(this);"/>
</td>
<td>
<table style="background-color: white;">
<tr>
<td style="border:solid 1px #FF6600; width:700px;"><div>決裁</div></td>
</tr>
<tr id="keisai_b_1_m" style="display:none;">
<td>
<table class="mazarine" style="background-color: #FF6600; border: solid 2px #FF6600; ">
<tr>
<th style="border-color: white; background-color: #FF6600;">
<div style="width: 160px;">決裁</div></th>
<td style="text-align: left; border-color: #FF6600; background-color: white;">
<div style="width: 120px;"></div></td>
<th style="border-color: #FF6600; background-color: #FF6600;">
<div style="width: 80px;">決済日</div></th>
<td style="width: 100px; text-align: left; border-color: #FF6600; background-color: white;">
<div style="width: 120px;"></div></td>
<th style="width: 80px; border-color: #FF6600; background-color: #FF6600;">
<div style="width: 80px;">決裁者</div></th>
<td style="width: 100px; text-align: left; border-color: #FF6600; background-color: white;">
<div style="width: 120px;"></div></td>
</tr>
<tr>
<th style="border-color: white; background-color: #FF6600;">
<div style="width: 160px;">連絡事項</div></th>
<td colspan="5" style="text-align: left; border-color: #FF6600; background-color: white;"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
关于HTML的Element的更多相关文章
- Spring配置文件标签报错:The prefix "XXX" for element "XXX:XXX" is not bound. .
例如:The prefix "context" for element "context:annotation-config" is not bound. 这种 ...
- 【解决方案】cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'. One of '{"http://java.sun.com/xml/ns/javaee":run-as, "http://java.sun.com/xml/ns/javaee":security-role-r
[JAVA错误] cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'. One o ...
- WebComponent魔法堂:深究Custom Element 之 从过去看现在
前言 说起Custom Element那必然会想起那个相似而又以失败告终的HTML Component.HTML Component是在IE5开始引入的新技术,用于对原生元素作功能"增强& ...
- WebComponent魔法堂:深究Custom Element 之 标准构建
前言 通过<WebComponent魔法堂:深究Custom Element 之 面向痛点编程>,我们明白到其实Custom Element并不是什么新东西,我们甚至可以在IE5.5上定 ...
- WebComponent魔法堂:深究Custom Element 之 面向痛点编程
前言 最近加入到新项目组负责前端技术预研和选型,一直偏向于以Polymer为代表的WebComponent技术线,于是查阅各类资料想说服老大向这方面靠,最后得到的结果是:"资料99%是英语 ...
- 深入理解DOM节点类型第五篇——元素节点Element
× 目录 [1]特征 [2]子节点 [3]特性操作[4]attributes 前面的话 元素节点Element非常常用,是DOM文档树的主要节点:元素节点是html标签元素的DOM化结果.元素节点主要 ...
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven'.
spring 配置文件报错报错信息:cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be ...
- MongoDB查询转对象是出错Element '_id' does not match any field or property of class
MongoDB查询转对象是出错Element '_id' does not match any field or property of class 解决方法: 1.在实体类加:[BsonIgno ...
- [LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...
- [LeetCode] Kth Smallest Element in a BST 二叉搜索树中的第K小的元素
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Not ...
随机推荐
- tab模块
#!/usr/bin/env python # python startup file import sys import readline import rlcompleter import ate ...
- Echarts 地图控件tooltip多行显示
直接上代码 var o = { "tooltip": { trigger: 'item', "formatter": function (params) { v ...
- Ubuntu14.04安装和配置ROS Indigo(一)
安装ROS 配置Ubuntu的软件源 配置Ubuntu要求允许接受restricted.universe和multiverse的软件源,可以根据下面的链接配置: https://help.ubuntu ...
- 支持.NET和移动设备的XLS读写控件XLSReadWriteII下载地址及介绍
原文来自龙博方案网http://www.fanganwang.com/product/3085转载请注明出处 读写任何单元值 数字型.字符型.布尔型以及错误型.但是你了解日期和时间型单元吗?在Exce ...
- 在oracle中创建空间索引
Oracle spatial可以方便的存储空间数据,大量的空间数据必需要使用空间索引去查询.在oracle中创建空间索引必需先建立元数据,否则无法创建索引.创建元数据的代码: insert into ...
- SQL语句查询所耗时间与效能的语句
1)SQL查询所耗时间语句 原理:记录当前时间1,执行SQL语句,记录当前时间2,显示时间2与时间1的差. 由于第一次执行的所耗时间为真实时间,之后会保存在缓存中,所以第二次之后的查询所耗时间都会比第 ...
- joinfetch之意义
既然被join的对象早晚都要用到,为什么要先从A表取这边的独享,再根据关联关系取B表中的对象,分两次或者多次进行,增加数据库的负载呢? 为什么不把A表和B表join成一张表,从这个组合表中把要取的对象 ...
- php大力力 [007节]php静态表量
2015-08-23 php大力力007. php静态表量 这里看一下高老师的视频讲解: 转帖: php中static静态类与static 静态变量用法区别 php中的静态变量的基本用法 转载 时间: ...
- iOS ARC和MRC混编
如果一个工程为MRC,其中需要添加ARC的文件: 选择target -> build phases -> compile sources ->单击ARC的文件将compil ...
- Raising Modulo Numbers_快速幂取模算法
Description People are different. Some secretly read magazines full of interesting girls' pictures, ...