手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表Tag:dom

DOM元素节点nodeType取值详解

nodeType的取值还是会经常用到的,但一般我们只用1和3,找了一下资料,1和3的含义是什么,才发现,原来是这样的。【部分资料来自:http://www.impng.com/web-dev/element-nodetype-values.html】

整数 常量
1 ELEMENT_NODE,普通元素节点,如<html>,<p>,<div>,<span>,<img>
2 ATTRIBUTE_NODE,元素属性
3 TEXT_NODE,文本节点
4 CDATA_SECTION_NODE,即<![CDATA[ ]]>
5 ENTITY_REFERENCE_NODE,实体引用,如&amp;&nbsp;
6 ENTITY_NODE,实体,如<!ENTITY copyright “Copyright 2010, impng. All rights reserved”]>
7 PROCESSING_INSTRUCTION_NODE,PI,处理指令,如<?xml  version=”1.0″?>
8 COMMENT_NODE,注释<!–   –>
9 DOCUMENT_NODE,根节点,即document.nodeType
10 DOCUMENT_TYPE_NODE,DTD,文档类型<!DOCTYPE   >
11 DOCUMENT_FRAGMENT_NODE,文档片段
12 NOTATION_NODE,DTD中定义的记号


需要注意的是,在IE下会直接跳过HTML中的空格/Tab/换行,而Firefox下空格会认为是一个节点,因此,对类似节点取nextSiblingpreviousSibling时,需要判断是否是元素节点。所以。要取某个节点下面的文字时,必须是类似这样的写法。

JavaScript代码
  1. function L(a) {  
  2.     var b = "";  
  3.     for (a = a.firstChild; a; a = a.nextSibling){  
  4.         if (a.nodeType === 3){  
  5.             b += a.nodeValue;  
  6.         } else if (a.nodeType === 1){  
  7.             b += L(a);  
  8.         }  
  9.     }  
  10.     return b  
  11. }  

Tags: nodetype, dom

苹果官方:Introduction to WebKit DOM Programming Topics

这是一篇来自苹果官方的教程,原来我也没想到过,居然可以用JS来调用Object-C中的东东。其实想想,这应该是可以,要知道,象maxthon这些浏览器,可就是早就能够调用他们的核心组件了,当然,也是用JS的。firefox也是类似。。。所以Safari应该也是可以支持的。
官方文章地址是:http://developer.apple.com/library/mac/#documentation/AppleApplications/Conceptual/SafariJSProgTopics/WebKitJavaScript.html

看看他们是怎么写的,
Important: This is a preliminary document. Although it has been reviewed for technical accuracy, it is not final. Apple is supplying this information to help you adopt the technologies and programming interfaces described herein. This information is subject to change, and software implemented according to this document should be vetted against final documentation. For information about updates to this and other developer documentation, you can check the ADC Reference Library Revision List. To receive notification of documentation updates, you can sign up for a free Apple Developer Connection Online membership and receive the bi-weekly ADC News e-mail newsletter. See http://developer.apple.com/products/for more details about ADC membership.)

还有。。。

Who Should Read This Document?

This document is designed for a number of different audiences:

  • If you are a web content developer—developing web sites and embedded JavaScript applications—you should read about Safari’s JavaScript support and how scripts operate within WebKit-based applications.

  • If you are a Cocoa and WebKit developer, you should read about how to integrate JavaScript into your WebKit views and how to enhance your user experience in doing so.

  • If you are a Dashboard developer, you should read about integrating JavaScript into your widgets to provide a better user experience and more advanced features to your users.

Organization of This Document

The topic contains the following articles:

See Also

  • Safari HTML Reference provides descriptions of HTML tags, attributes, and other markup.

  • Safari CSS Reference provides descriptions of CSS properties and constants.

  • Safari Web Content Guide provides information about designing web content for iPhone.

  • Dashboard Programming Topics provides information on the technologies available to you when creating a Dashboard widget. Additional Dashboard documents and sample code can be found in the Reference Library > Apple Applications > Dashboard.

  • Apple JavaScript Coding Guidelines provides general tips about the JavaScript programming language.

  • The Reference Library > Apple Applications > Safari section of the ADC Reference Library provides useful information on WebKit, the technology that provides Apple’s JavaScript runtime.

果然还是官方的资料最多,NND,平时搜点资料都搜不到,还是官方给的方案最多啊。

Tags: javascript, object-c, dom, webkit