关于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 ...
随机推荐
- C#获取指定日期为一年中的第几周
/// <summary> /// 获取指定日期,在为一年中为第几周 /// </summary> /// <param name="dt">指 ...
- SharePoint 2013 开发——获取用户配置文件属性内容(User Profile)
博客地址:http://blog.csdn.net/FoxDave 本篇我们应用SharePoint CSOM(.NET)来读取用户配置文件的信息,个人开始逐渐倾向于客户端模型,因为不用远程登录到 ...
- table td的宽度详解
前言:一直总觉得td的宽度好难驾驭,但万事万物总是有规律的.就像亮剑说的:不用因为怕八路就敬而远之,应该靠上去,熟悉他们,了解他们. 正文: Table只有Table的宽度是可 ...
- hdu3473 线段树 划分树
//Accepted 28904 KB 781 ms //划分树 //所求x即为l,r区间排序后的中位数t //然后求出小于t的数的和sum1,这个可以用划分树做 //求出整个区间的和sum,可以用O ...
- unity3d打包和包的使用
打包: ①Assets下新建文件夹Editor和steamingAssets ②对选定文件打包: using UnityEngine; using UnityEditor; using System. ...
- 如何修改svn的密码或重新输入用户名密码
在Eclipse 使用SVN 的过程中大多数人往往习惯把访问SVN 的用户名密码自动保存起来以便下次自动使用,不要再次手工输入,而此时(自动保存密码后),svn又不存在一个显式的登陆框了,但是有些时候 ...
- 2016 - 1- 22 NSURLConnetction --- POST请求
一:与上一篇博客中的GET方法类似 只不过需要多注意,如果要改变请求的类型,需要生成NSMutableURLRequest对象才可以设置请求的类型. NSURL *url = [NSURL URLW ...
- yii2归档安装
1.http://www.yiiframework.com/download/ 下载文件 2.如果inint.bat文件一闪而过,没有提示是开发还是生产环境 用编辑器(phpstorm)打开文件在对应 ...
- ERP仓库管理系统查询(十)
需求: 1.根据仓库编号,获取仓库信息绑定至页面相关控件. 2.根据仓库编号,获取管理员信息绑定到页面相关控件 修改的界面: <%@ Page Language="C#" ...
- 14、C#基础整理(函数)
函数 1.概念:是一个带有输入参数.输出参数.返回值的代码块. 2.写法: 修饰符 返回值类型 函数名(输入参数,输入参数) { 方法段 return 返回值; } 3.注释: (1)输入参数格式 ...