JavaScript基礎之DOM Document對象

//Document對象
        //屬性
        element document.documentElement;       //返回文檔根節點 HTML文檔返回HTML元素
        element document.head;                  //返回文檔的head元素
        element document.body;                  //返回文檔的body元素
        element document.activeElement;         //返回文檔當前得到焦點的元素

        string  document.referrer;              //返回載入當前文檔的來源文檔的URL 若是沒有則爲null
        string  document.URL;                   //返回當前文檔完整的URL
        string  document.domain;                //返回當前文檔服務器域名
        string  document.baseURI;               //返回文檔的基礎URI
        string  document.cookie;                //設置或返回文檔的cookie
        string  document.doctype;               //返回文檔類型聲明
        string  document.title;                 //返回當前文檔的標題
        string  document.inputEncoding;         //返回處理該文檔使用的字符集
        string  document.lastModified;          //返回文檔最後的修改時間
        string  document.readyState;            //返回文檔加載狀態  uninitialized loading loaded interactive complete

                //數組集合對象 屬性length返回集合長度  方法[index]、item(index)、namedItem(id) index指定索引 id指定id屬性值
        array   document.embeds;                //返回文檔全部的embed元素集合
        array   document.forms;                 //返回文檔全部的form元素集合
        array   document.images;                //返回文檔全部的image元素集合
        array   document.links;                 //返回文檔中全部的a元素和area元素集合 若是沒有href屬性 將不會包含
        array   document.scripts;               //返回文檔中全部的script元素集合

        //方法
        void    document.addEventListener(string event, function, [bool useCapture = false]);    //對文檔添加事件監聽
        void    document.removeEventListener(string event, function, [bool useCapture = false]); //對文檔移除事件監聽
        object  document.adoptNode(object node);            //返回從另外一個文檔移動到當前文檔的節點
        object  document.importNode(object node, bool deep);//返回從另外一個文檔複製到當前文檔的節點 deep爲true則複製子節點
        attr    document.createAttribute(string name);      //創造一個屬性節點name
        object  document.createComment(string text);        //創造一個內容爲text的註釋節點
        element document.createElement(string name);        //建立一個元素節點name
        object  document.createTextNode(string text);       //建立一個內容爲text的文本節點

        element document.getElementById(string id);         //返回指定ID的元素
        element document.getElementsByTagName(string tag);  //返回指定tag的全部元素
        element document.getElementsByName(string name);    //返回指定name的全部元素
        element document.getElementsByClassName(str class); //返回指定class的全部元素
        element document.querySelector(string CSS);         //返回CSS選擇器匹配的第一個元素
        element document.querySelectorAll(string CSS);      //返回CSS選擇器匹配的全部元素         

        bool    document.hasFocus();                        //檢查文檔是否具備焦點
        void    document.normalize();                       //合併相鄰的文本節點並刪除空的文本節點
        void    document.write(exp1, exp2, exp3, ...);      //向文檔中寫入HTML或JavaScript代碼
        void    document.writeln(exp1, exp2, exp3 ...);     //同document.write() 可在每一個表達式後寫一個換行符。
相關文章
相關標籤/搜索