关于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 ...
随机推荐
- [开发笔记]-VS2012打开解决方案崩溃或点击项目崩溃
下午在使用VS2012建立Service服务项目时,只要一切换到设计视图页面中,VS就崩溃重启,从网上找了一种方法来解决,测试可行.但导致该问题的原因未知. 解决方案: 步骤1:开始-->所有程 ...
- IT公司100题-1-二叉树转换为双链表
问题描述: 输入一棵二元查找树,将该二元查找树转换成一个排序的双向链表.要求不能创建任何新的结点,只调整指针的指向. 10 / \ 6 14/ \ / \4 8 1 ...
- 入門必學NO.1 Android 初學特訓班(第四版) 目錄
第 01 章 敲開 Android 的開發大門工欲善其事,必先利其器,要學習 Android 應用程式,先取得功能強大的開發工具,就可讓學習事半功倍. 1.1 Android 是啥米?1.2 建構 A ...
- HDU 3333 树状数组离线查询
题目大意: 询问区间内不同种类的数的数值之和 这里逐个添加最后在线查询,会因为相同的数在区间内导致冲突 我们总是希望之后添加的数不会影响前面,那么我们就在添加到第i个数的时候,把所有在1~i 的区间的 ...
- 如何在redhat下安装WineQQ
使用过redhat的朋友都知道在redhat下要使用聊天工具例如:腾讯QQ只能是用网页QQ,但网页QQ始终用得不尽人意,下面我将给大家介绍一种在redhat下安装WineQQ的方法,让你能在redha ...
- 从协议VersionedProtocol开始1
Phase 0: Make a plan You must first decide what steps you're going to have in your process. It sound ...
- (转)如何学好C语言,一个成功人士的心得!
zidier111发表于 2013-1-26 08:59:05 今 天,我能够自称是一个混IT的人,并能以此谋生,将来大家能一次谋生,都要感谢两个人:克劳德.香农和约翰.冯.诺依曼,是他们发现了所 ...
- [转]Android系统Surface机制的SurfaceFlinger服务简要介绍和学习计划
转自:Android系统Surface机制的SurfaceFlinger服务简要介绍和学习计划 前面我们从Android应用程序与SurfaceFlinger服务的关系出发,从侧面简单学习了Surfa ...
- for循环和while循环的区别
public class Xunhuanqubie { public static void main(String[] args){ int i = 0; while(i<8){ System ...
- HDU 4417 - Super Mario ( 划分树+二分 / 树状数组+离线处理+离散化)
题意:给一个数组,每次询问输出在区间[L,R]之间小于H的数字的个数. 此题可以使用划分树在线解决. 划分树可以快速查询区间第K小个数字.逆向思考,判断小于H的最大的一个数字是区间第几小数,即是答案. ...