- 浏览: 1045354 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
nieanan:
感谢,很有帮助。
eclipse 改变JAVA_HOME路径 -
Orange_killer:
写的什么东西,文不对题
Hibernate Search大数据量手动建立索引 -
xiaoasha:
org.eclipse.equinox.servlet.api ...
《OSGI实战》遇到的问题 -
powertech:
写的挺细,有用!
SyntaxError: Non-ASCII character Python、Unicode和中文 -
huang_yong:
public class XMLUtil {
pri ...
XStream 去除生成的XML节点的class="list"
Last updated: Februrary 27th, 2006
The term "nodes" is just a fancy way of referring to all the elements in a document, whether it's a particular DIV, or the text contained inside it. The "nodeType" property of the DOM is very helpful in determining exactly the type of the node you're currently accessing, which isn't always so apparent. Here are the possible values returned by "nodeType":
nodeType values chart
1 | ELEMENT_NODE |
2 | ATTRIBUTE_NODE |
3 | TEXT_NODE |
4 | CDATA_SECTION_NODE |
5 | ENTITY_REFERENCE_NODE |
6 | ENTITY_NODE |
7 | PROCESSING_INSTRUCTION_NODE |
8 | COMMENT_NODE |
9 | DOCUMENT_NODE |
10 | DOCUMENT_TYPE_NODE |
11 | DOCUMENT_FRAGMENT_NODE |
12` | NOTATION_NODE |
Consider the following HTML code:
<div id="adiv"><b>Some text</b></div> <script type="text/javascript"> alert(document.getElementById("adiv").nodeType) //DIV element. Alerts 1 alert(document.getElementById("adiv").firstChild.nodeType) //B element. Alerts 1 </script>
With the above HTML block, you don't really need the "nodeType" property to tell you the types of the three nodes you're accessing. But consider this slightly modified example:
<div id="adiv"> <b>Some text</b></div> <script type="text/javascript"> alert(document.getElementById("adiv").nodeType) //DIV element. Alerts 1 alert(document.getElementById("adiv").firstChild.nodeType) //Alerts 1 or 3, depending on browser. </script>
Here I've added a blank space in front of the B element. To some browsers such as Firefox, a blank space is considered a text node (nodeType=3) just like regular text, while in others such as IE, they are not. Due to this, "the next node" after the DIV element varies depending on which browser you ask, with Firefox saying it's a text node, while IE says it's an element node (B element). Without the help of the nodeType property when traversing the document, your script may very well lose its place.
nodeName property
If the integer value returned by the "nodeType" property is too abstract for you, a more human, albeit less robust way, of returning the type of a node is using the "nodeName" property. It returns a string indicating the name of the node. Returned value is in uppercase. Here are some common "nodeName" property values returned:
#comment | This is a comment node. |
#document | This is the document node. |
element.tagName | The tagName of the element, indicating this is an element at the same time. |
Attri.name | The name of the attribute, indicating this is an attribute node at the same time. |
#text | This is a text node. |
For example:
if (document.getElementById("test").firstChild.nodeName=="DIV") alert("This is a DIV")
nodeValue property
The "nodeValue" property is a read/write property that reflects the current value of a node. For text nodes, the content of the node is returned, while for attribute nodes, the attribute value. Null is returned for Document and element nodes. Use this property to alter the contents of a text or attribute node.
<div id="test">Old text</div> <script type="text/javascript"> if (document.getElementById("test").firstChild.nodeName=="#text") document.getElementById("test").firstChild.nodeValue="New text" </script>
<script type="text/javascript"><!----></script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script> <script type="text/javascript"><!----></script>
发表评论
-
Window.ShowModalDialog的参数问题(父窗体向子窗体传值)
2010-03-22 12:57 2871基本介绍: showModalDialog() ... -
Textarea在光标停留处插入文字
2010-03-17 15:51 1812<!-- function Insert(str ... -
dojo.io.iframe.send 获得返回数据
2010-02-23 20:28 5363使用dojo.io.iframe.send提交表单时发现老是取 ... -
请问用javascript如何实现求两个日期相隔的天数
2010-01-21 17:32 1948方法一: /******************* ... -
JavaScript利用ActiveX导出Excel,Word
2010-01-15 16:03 1665<HTML> <HEAD> ... -
JavaScript检查ActiveX控件是否已经安装过
2010-01-14 16:52 1905function detectPlugin(CLSID,fu ... -
通过frames.frameElement获得当前页面iframe对象
2009-10-21 09:33 2651如果有个页面嵌在一个iframe里面,现在在这个页面里面如何获 ... -
textarea中的OnChange事件与onkeyup事件
2009-09-24 14:25 11669有个textarea,想实现字符改变,显示的字符数也随着变化 ... -
javascript检测document关闭的好方法
2009-09-23 15:31 1531如果使用window.unload或者window.befor ... -
string 扩展endWith
2009-04-03 17:45 1562string 扩展endWith <SCRIPT ... -
用JS过滤html标签的代码
2009-03-26 21:40 8533如果只是把< >类似的标记统统去掉,并不需要考虑别 ... -
Iframe实现的ajax如何实现POST请求?
2008-11-21 17:21 9779曾经看到有人用iframe来实现AJAX,我想了一下 ... -
JavaScript获取HTML DOM节点元素的方法的总结
2008-10-31 16:43 2848在Web应用程序特别是Web2.0程序开发中,经常要获取页面中 ... -
firefox 2 marquee兼容
2008-10-31 16:40 4631新作的项目里面有个页面用到了<marquee>标签 ... -
navigator 判断浏览器
2008-10-31 16:11 1358The navigator object The naviga ... -
不用js多浏览器兼容纯DIV/CSS对联漂浮广告代码
2008-10-20 10:04 2877CSS代码: .r1{width:80px;height:80 ... -
删除已经加载的css stylesheet
2008-10-17 16:14 1210想要删除已经加载的css stylesheet (<li ... -
mac下面的safari不支持element.attribute['attrName'].value
2008-10-15 17:48 1599今天又发现mac下面的一个问题: mac下面的safari ... -
xml作为参数的兄弟们要注意了
2008-10-13 10:45 1869将xml作为参数的兄弟们注意了,请将你们的xml,encode ... -
safari中javascript的跨域权限更加严格
2008-09-12 11:23 2339写过ajax的人都知道,如果当前页面是http://www.y ...
相关推荐
语法:elementNode.nodeType 节点编号: 节点名称: 1 Element 2 Attribute 3 Text 4 CDATA Section 5 Entity Reference 6 Entity 7 Processing Instrucion 8 Comment 9 Document 10 Document Type 11...
nodeName、nodeValue 以及 nodeType 包含有关于节点的信息。nodeName 属性含有某个节点的名称。 元素节点的 nodeName 是标签名称 属性节点的 nodeName 是属性名称 文本节点的 nodeName 永远是 #text 文档节点的 ...
if (element.nodeType == 3 /*Node.TEXT_NODE*/) { var text = element.data; if (!preformatted) { //text = text.replace(/\n|\r|\t/g, ” “); text = normalizeNewlines(text); } return text; } if (ele
本文详细介绍了nodeName、nodeValue和nodeType属性
主要介绍了nodeType属性返回被选节点的节点类型。需要的朋友可以过来参考下,希望对大家有所帮助
firstElementChild 访问一元素的这个属性必须将该nodeType 1 元素第一子节点引用返回为 Element 对象。如果该被访问元素属性没有任何子节点,或者如果所有这些子节点都不是元素节点, 那么该属性必须返回 null。 ...
if (element.self || element.nodeType === 9) return new Sys.UI.Point(0,0); var clientRect = element.getBoundingClientRect(); if (!clientRect) { return new Sys.UI.Point(0,0); } var ownerDocument =...
nodeName 属性含有某个节点的名称。 元素节点的 nodeName 是标签名称 属性节点的 nodeName 是属性名称 文本节点的 nodeName 永远是 #text ...元素element1属性attr2文本text3注释comments8文档document9补充: 值-元素
Neos.NodeType.CodeMirror 允许在 TYPO3 Neos 中使用 codeMirror 样式代码片段的节点类型将此添加到您的 composer.json 以启用代码片段节点类型: { "repositories": [ { "type": "git", "url": ...
开放式堆栈用于与 OpenStack IaaS 交互的 TOSCA NodeType 和 ImplementationArtifact输入所有网络方法至少需要两个输入: 证书端点API 它们的语法必须是: 凭据:{"auth":{"tenantId":"???","passwordCredentials":{...
这些属性直接对应 interface 定义的,附加的约束是它们只操作 nodeType 1(即 Element 节点),忽略 Text、Comment 和其他 nodeType。 十有八九,这正是 Web 开发人员想要做的事情,因此使用这些将。 polyfill 还将...
Neos NodeType:ContentReferences 该程序包实现节点类型ContentReferences。 它显示引用的节点。 这最初是Neos.NodeTypes包的一部分。 贡献 如果您想为Neos做出贡献,请查看它是用于开发的存储库,所有请求请求都...
Neos NodeType:HTML 该程序包实现了一个节点类型Html以显示任意html代码。 这最初是Neos.NodeTypes包的一部分。 贡献 如果您想为Neos做出贡献,请查看它是用于开发的存储库,所有请求请求都应包含在其中。
while(tempObj.nodeType != 1 && tempObj.previousSibling != null){ tempObj = tempObj.previousSibling; } return (tempObj.nodeType == 1)?tempObj:false; }, //Find the first sibling of the current ...
我们经常使用nodeType==1判断元素是否是一个HMTLElement元素。页面上的元素都是节点(Node),有元素节点(Element Node)、属性节点(Attribute Node)、文本节点(Text Node)等。w3c nodeType 的定义如下 const unsigned ...
代码如下: function cleanWhitespace(element){ //如果不提供参数,则...= null){ //保存当前节点的下个节点 tmp=cur.nextSibling //如果节点为文本节点,应且包含空格 if ( cur.nodeType == 3 && ! /\S/.test(cur.n