تصف هذه المقالة طريقة JS التي تتحكم في التوليد الديناميكي من جداول الصف والعمود التعسفي على صفحة الويب. شاركه للرجوع إليه. التحليل المحدد هو كما يلي:
هذا هو تأثير رمز بسيط للغاية لإنشاء الجداول عبر الإنترنت باستخدام JS
من خلال رمز وظيفة JS ، يمكنك إنشاء الجدول الذي تحتاجه تلقائيًا عن طريق إدخال عدد الصفوف والأعمدة تلقائيًا
بالطبع ، يمكنك أيضًا تمديد رمز JS لتنفيذ أشكال مختلفة من النص
انسخ الرمز كما يلي: <html>
<head>
<title> js قم بإنشاء الجداول </title> ديناميكيًا
<type type = "text/css">
جدول {font-size: 14px ؛}
</style>
</head>
<body>
<script language = "javaScript">
دالة tableclick (name1 ، name2 ، name3) {
trow = name1.value ؛
tcol = name2.value ؛
TV = name3.value ؛
if ((trow == "") || (tcol == "") || (tv == "")) {
تنبيه ("يرجى ملء شروط صنع النموذج") ؛
}
آخر{
r = parseint (trow) ؛
C = parseint (tcol) ؛
Table1 (R ، C ، TV) ؛
}
}
دالة TableValue (A ، AI ، الصفوف ، العقيد ، شارع) {
int1 = A.Length ؛
لـ (i = 0 ؛ i <الصفوف ؛ ++ i) {
لـ (j = 0 ؛ j <col ؛ ++ j) {
if ((j == 0) && (ai> = int1)) {break ؛}
if (ai> = int1) {
str = str+"<td scope = 'col'> </td>" ؛
}
آخر{
if (j == 0) {
str = str+"<tr> <th scope = 'col'>"+(a [ai ++])+"</th>" ؛
}
آخر{
if (j == col-1) {
str = str+"<td scope = 'col'>"+(a [ai ++])+"</td>" ؛
}
آخر{
str = str+"<td scope = 'col'>"+(a [ai ++])+"</td>" ؛
}
}
}
}
str = str+"</tr>" ؛
}
إرجاع شارع
}
وظيفة Table1 (Row ، Col ، Str1) {
var str = "" ؛
a = new array () ؛
s = سلسلة جديدة (str1) ؛
A = S.Split ("#") ؛
int1 = A.Length ؛
AI = 0 ؛
if (col <= int1) {
str = str+"<table width = '300' border = '4'>" ؛
لـ (i = 0 ؛ i <col ؛ ++ i) {
إذا (i == 0) {
str = str+"<tr> <th scope = 'col'>"+(a [ai ++])+"</th>" ؛
}
آخر{
if (i == (col-1)) {
str = str+"<th scope = 'col'>"+(a [ai ++])+"</th> </tr>" ؛
}
آخر{
str = str+"<th scope = 'col'>"+(a [ai ++])+"</th>" ؛
}
}
}
if (int1> col) {
if (row> 1) {
str = tableValue (a ، ai ، row-1 ، col ، str) ؛
}
}
str = str+ "</table>" ؛
aa.innerhtml = str ؛
}
}
</script>
<form name = "form1" method = "post" Action = "">
<p> <b> رقم السطر: </b>
<input name = "name1" type = "text" value = "4">
<b> عدد الأعمدة: </b>
<input name = "name2" type = "text" value = "4">
<type type = "button" name = "submit3" value = "إنشاء جدول" onClick = "tableclick (document.form1.name1 ، document.form1.name2 ، document.form1.name3)" </p>
<p> <b align = "top"> قيمة الجدول: </b> </p>
<p>
<input name = "name3" wrap = "virtual" value = "col1#col3#col3#col4#row1#a1#a2#a3#row2#b1#b2#b3#row3#c1#c2#c3">
</p>
</form>
<div id = "aa"> </viv>
</body>
</html>
آمل أن تكون هذه المقالة مفيدة لبرمجة JavaScript للجميع.