English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
-----الاستيراد
كل مستند HTML المحمل في المتصفح يصبح Object Document.
يخول لنا تعريف Document Object من خلال السكربت الوصول إلى جميع العناصر في صفحة HTML.
الخصائص
1 document.anchors يعود إلى مرجع جميع عناصر الإشارات في المستند. بالإضافة إلى document.links/document.forms/document.images إلخ
2 document.URL يعود إلى عنوان URL الحالي للصفحة.
3 document.title يعود إلى عنوان الحالي للصفحة.
4 document.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 مجموعة هي شكل بيانات مشابه لـ Array، ولكنها توفر فقط خاصية length، مثل طرق push و pop في Array.
6 document.getElementById() يعود بم-reference إلى العنصر الأول الذي يحتوي على id المحدد.
7 document.getElementsByName() يعود بمجموعة من العناصر التي تحتوي على الاسم المحدد.
8 document.getElementsByTagName() يعود بمجموعة من العناصر التي تحتوي على اسم العلامة المحدد.مجموعة من العناصر.
9 document.write() يكتب تعبيرات HTML أو كود JavaScript إلى المستند. ملاحظة: عند استخدام طريقة write بعد تحميل مستند HTML، سيتم تغطية محتوى HTML الأصلي بمحتوى write.
<!DOCTYPE html> <html lang="en"> <!DOCTYPE html> <head> </head> </body> <p>hello world</p> <script> document.write('hahahh') </script> </body> </html>
هذا هو كل محتوى التفصيلات المفصلة للخصائص والأساليب الشائعة لـ document Object في DOM التي قدمها لك المحرر، نأمل أن تدعموا دروسنا بالشديد~