关于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 ...
随机推荐
- Chrome 开发者工具有了设备模拟器
今天从哥们那里学到了一个小技巧,使用chrome自带的多设备模拟器来调试页面在不同设备下的显示效果. 特地上网查了一下,记录一下. 如果想要在 Chrome 上测试网站在不同设备,不同分辨率的显示情况 ...
- 数据结构-Hash表
实现: #ifndef SEPARATE_CHAINING_H #define SEPARATE_CHAINING_H #include <vector> #include <lis ...
- git初识
下载网上的开发员的项目 git clone https://github.com/xxxxxx/test.git 下载好,进入刚下载的好的test项目目录,可以修改对应的代码,然后 git statu ...
- java批量插入数据进数据库中
方式1: for循环,每一次进行一次插入数据. 方式2: jdbc的preparedStatement的batch操作 PreparedStatement.addBatch(); ...... Pre ...
- 提示框alertmsg
初始化: 1.Data属性:DOM添加属性data-toggle="alertmsg",并定义type及msg参数 示例代码: <button type="butt ...
- jquery api调用
本框架内置组件以及部分插件都可以通过jquery选择器进行API调用,支持链式操作,如下示例. <script type="text/javascript"> $(&q ...
- SharePoint 2013 开发——发布SharePoint应用程序
博客地址:http://blog.csdn.net/FoxDave 前几篇我们介绍了开发.部署和调试SharePoint应用程序的基础,本篇介绍更实用的操作,当我们开发一个SharePoint应用 ...
- 2014年2月份第3周51Aspx源码发布详情
NHibernateSample示例源码 2014-2-21 [VS2010]源码描述:NHibernateSample示例源码,利用NHibernate配置数据库相关映射,方便快捷,欢迎感兴趣用户 ...
- 2013年7月份第3周51Aspx源码发布详情
批量重命名文件工具源码 2013-7-19 [VS2010]功能介绍:这是一个新型的文件重命名,主要用了TreeView(树形视图)来选择文件夹,批量进行文件重命名.其中,有"编号在前,编 ...
- python视频教程:十分钟快速入门python
想要学习python这门语言,却始终找不到一个全面的Python视频教程,倘若你是真心想学好一门语言,小编建议你亲自动手实践的.下面来看看入门python的学习教程. Python的语言特性 Pyth ...