English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
-----導入
ブラウザに読み込まれたすべてのHTMLドキュメントはDocumentオブジェクトになります。
Documentオブジェクトを使用して、スクリプトからHTMLページ内のすべての要素にアクセスできます。
属性
1 document.anchors ドキュメント内のすべてのAnchorオブジェクトへの参照を返します。document.linksもあります/document.forms/document.imagesなど
2 document.URL 現在のドキュメントのURLを返します
3 document.title 現在のドキュメントのタイトルを返します
4 document.body body要素ノードを返します
方法
1 document.close() document.open()メソッドで開いた出力ストリームを閉じ、選択されたデータを表示します。
<!DOCTYPE html> <html> <head> <script> function createDoc() { var w=window.open(); w.document.open(); w.document.write("<h1>Hello World!</h1)"); w.document.close(); } </script> </head> <body> <input type="button" value="New document in a new window" onclick="createDoc()"> </body> </html>
2 document.createElement() 要素ノードを作成します。
<!DOCTYPE html> <html lang="en"> <!DOCTYPE html> <head> </head> <body> <p>hello world</p> <script> var a = document.createElement('hr'); document.body.appendChild(a) </script> </body> </html>
3 document.createAttribute() 属性ノードを作成します。
<!DOCTYPE html> <html> <body> <p id="demo">Click the button to make a BUTTON element.</p> <button onclick="myFunction()">Try it</button> <script> function myFunction() { var btn=document.createElement("BUTTON"); document.body.appendChild(btn); }; </script> </body> </html>
4 document.createTextNode() は、テキストノードを作成します。
<!DOCTYPE html> <html lang="en"> <!DOCTYPE html> <head> </head> <body> <p>hello world</p> <script> var a = document.createTextNode('hahahah'); document.body.appendChild(a) </script> </body> </html>
5 document.getElementsByClassName() は、ドキュメント中のすべての指定されたクラス名を持つ要素コレクションを返し、NodeList オブジェクトコレクションとして提供します。NodeList オブジェクトコレクションは、配列に似たデータ形式で、length 属性のみを提供し、配列の push、pop メソッドなどは提供していません。
6 document.getElementById() は、指定された id を持つ最初のオブジェクトへの参照を返します。
7 document.getElementsByName() は、指定された名前を持つオブジェクトコレクションを返します。
8 document.getElementsByTagName() は、指定されたタグ名を持つオブジェクトコレクションを返します。オブジェクトコレクション。
9 document.write() は、HTML 表現や JavaScript コードをドキュメントに書き込む。注意:HTML ドキュメントが読み込まれた後に write メソッドを使用すると、write コンテンツが元の HTML ドキュメントを上書きします。
<!DOCTYPE html> <html lang="en"> <!DOCTYPE html> <head> </head> <body> <p>hello world</p> <script> document.write('hahahh') </script> </body> </html>
これで、編集者が皆さんに提供した js 基礎の DOM 中の document オブジェクトの常用属性メソッドの詳細内容がすべてです。皆さん、チュートリアルのサポートと歓声をたくさんしてください~