تصف هذه المقالة طريقة إنشاء divs ديناميكيًا في JavaScript. شاركه للرجوع إليه. طريقة التنفيذ المحددة هي كما يلي:
نسخة الكود كما يلي:
<! doctype html public "-// w3c // dtd xhtml 1.0 transitional // en"
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv = "content-type" content = "text /html ؛ charset = utf-8" />
<title> الأصلي JavaScript Creation Div </title>
<script>
window.onload = function () {
var odiv = document.createElement ("div") ؛ // إنشاء div
var orpan = document.createElement ("span") ؛ // إنشاء فترة
Odiv.Style.csStext = "العرض: 200px ؛ الارتفاع: 200px ؛ الخلفية:#636363 ؛
محاذاة النص: مركز ؛ خط الارتفاع: 220 بكسل "؛ // إنشاء نمط CSS لـ Div
//odiv.id="box "؛ // قم بإنشاء معرف Div كمربع
//odiv.classname="box "؛ // فئة Div هي المربع
Odiv.Appendchild (Ospan) ؛ // إنشاء فترة في Div
document.body.appendchild (ODIV) ؛ // إنشاء Div في الجسم
}
</script>
</head>
<body>
</body>
</html>
آمل أن تكون هذه المقالة مفيدة لبرمجة JavaScript للجميع.