关于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 ...
随机推荐
- MONGODB 查询
1,mongoDB 取模运算:db.person.find({index:{$mod:[5,1]}})db.person.find({index:{$not:{$mod:[5,1]}}})2,name ...
- cssTex
var head= document.getElementById("head");head.style.cssText="width:200px;height:70px ...
- 基于MVC模式的应用框架之struts
1.struts开发步骤 引入struts的jar包: 在web.xml中引入struts的核心功能,配置struts核心过滤器:(如果项目中用到了其他过滤器,要放在struts过滤器之前,否则会失效 ...
- 项目管理软件---redmine安装配置
redmine是一个开源的项目管理软件,其主页是:http://www.redmine.org redmine是基于Ruby on Rails框架的,跨平台和跨数据库. 安装过程 ========== ...
- GoldenGate中使用strcat和strext进行数据转换
在OGG中可以对源字段的内容进行合并或拆分,从而实现类似于“ETL”的功能.strcat(s1,s2,s3,,,):用于合并字串:strext(str, start, end):用于获取指定位置的字串 ...
- 关于oracle存储过程的一些知识点
一.创建一个存储过程,批量清空数据库中所有表的数据. --清空数据库中所有表的数据 create or replace procedure truncateAllTables as v_sql ); ...
- socket.io 入门教程
转载自:http://deadhorse.me/nodejs/2011/12/29/socket.io_induction.html socket.io socket.io是一个以实现跨浏览器.跨平台 ...
- poll函数和串口设置
2015.1.24 今天星期六,多云,早晨8:17起床的,今天是来南京起床最迟的一天,因为昨晚睡得有点迟,今天又不用上课,整个人有点放松.收拾好来到教室,教室门没有开,胡明也到了,其他人还在宿舍睡觉, ...
- C# 封装一个钩子类
利用C#设置钩子函数,并封装成类.如果想要实现全局钩子的话,必须将实现的代码封装到类库里. using System; using System.Collections.Generic; using ...
- 瓷砖铺放 (状压DP+矩阵快速幂)
由于方块最多涉及3行,于是考虑将每两行状压起来,dfs搜索每种状态之间的转移. 这样一共有2^12种状态,显然进行矩阵快速幂优化时会超时,便考虑减少状态. 进行两遍bfs,分别为初始状态可以到达的状态 ...