يصف مثال المقالة طريقة توليد ألوان خلفية الويب بشكل عشوائي بواسطة JS. شاركه للرجوع إليه. طريقة التنفيذ المحددة هي كما يلي:
انسخ الرمز كما يلي: <html>
<head>
<title> المؤثرات الخاصة JS التي تم إنشاؤها بشكل عشوائي لون خلفية صفحة خلفية </title>
<style>
.30pt {font-size: 30pt ؛ color:#de3076}
</style>
<script language = "javaScript">
<!-
color = new Array ("0" ، "3" ، "6" ، "9" ، "C" ، "F") ؛
السرعة = 250 ؛
document.bgColor = "fffff" ؛
bg = new array ("ffffff" ، "ffffff" ، "ffffff") ؛
وظيفة البداية () {
document.form.col1.value = "x" ؛ document.form.col2.value = "x" ؛
document.form.col3.value = "x" ؛ أنا = 0 ؛ لفة (السرعة) ؛
}
دالة لفة (speedb) // العجلات لفة
{
if (document.form.col1.value == "x") {
document.form.c1.value = document.form.b1.value ؛
document.form.b1.value = document.form.a1.value ؛
document.form.a1.value =
اللون [Math.Round (Math.Random ()*10) ٪ 6]+
اللون [Math.Round (Math.Random ()*10) ٪ 6] ؛ // استخدم وظائف عشوائية لإنشاء قيم الألوان على العجلة
}
if (document.form.col2.value == "x") {
document.form.c2.value = document.form.b2.value ؛
document.form.b2.value = document.form.a2.value ؛
document.form.a2.value =
اللون [Math.Round (Math.Random ()*10) ٪ 6]+
اللون [Math.Round (Math.Random ()*10) ٪ 6] ؛
}
if (document.form.col3.value == "x") {
document.form.c3.value = document.form.b3.value ؛
document.form.b3.value = document.form.a3.value ؛
document.form.a3.value =
اللون [Math.Round (Math.Random ()*10) ٪ 6]+
اللون [Math.Round (Math.Random ()*10) ٪ 6] ؛
}
setTimeout ("Roll ("+speedb+")" ، speedB) ؛
}
توقف الوظيفة (العقيد) // تتوقف العجلة
{
if (col == 1) {document.form.col1.value = "" ؛ i ++ ؛}
if (col == 2) {document.form.col2.value = "" ؛ i ++ ؛}
if (col == 3) {document.form.col3.value = "" ؛ i ++ ؛}
إذا (i == 3) {
bg [0] = document.form.a1.value+
document.form.a2.value+
document.form.a3.value ؛
bg [1] = document.form.b1.value+
document.form.b2.value+
document.form.b3.value ؛
bg [2] = document.form.c1.value+
document.form.c2.value+
document.form.c3.value ؛
SpeedB = 500000 ؛ لفة (speedb) ؛
}
}
وظيفة عرض (رسالة) // معاينة اللون
{
document.bgColor = bg [letter] ؛
document.form.color.value = "#"+bg [letter] ؛
}
->
</script>
</head>
<centre>
<br> <br> <br> <br>
<name form = "form">
<الجدول cellpadding = 2 الحدود = 1>
<tr> <td align = center>
<type type = text name = "a1" size = 3 onfocus = "this.blur ()" value = "">
<type type = text name = "a2" size = 3 onfocus = "this.blur ()" value = "">
<type type = text name = "a3" size = 3 onfocus = "this.blur ()" value = "">
<نوع الإدخال = زر OnClick = "View (0)" value = "Preview"> <br>
<type type = text name = "b1" size = 3 onfocus = "this.blur ()" value = "">
<type type = text name = "b2" size = 3 onfocus = "this.blur ()" value = "">
<type type = text name = "b3" size = 3 onfocus = "this.blur ()" value = "">
<نوع الإدخال = زر OnClick = "View (1)" value = "Preview"> <br>
<type type = text name = "c1" size = 3 onfocus = "this.blur ()" value = "">
<type type = text name = "c2" size = 3 onfocus = "this.blur ()" value = "">
<type type = text name = "c3" size = 3 onfocus = "this.blur ()" value = "">
<نوع الإدخال = زر OnClick = "View (2)" value = "Preview"> <br>
<نوع الإدخال = زر OnClick = "STOP (1)" value = "x" name = "col1">
<نوع الإدخال = زر OnClick = "STOP (2)" value = "x" name = "col2">
<نوع الإدخال = زر OnClick = "STOP (3)" value = "x" name = "col3">
</td>
<td valign = middle align = center>
<نوع الإدخال = زر OnClick = "begr ()" value = "start!"> <p>
<الجدول bgcolor = fffff الحدود = 1 cellpacing = 0>
<tr> <td align = center valign = middle> اضغط على "x" وتتوقف العجلة ... <p>
bg color = <input type = text size = 7 value = "#ffffff" name = color>
</td> </tr>
</table>
</td> </tr>
</table>
</form>
</center>
<Table Class = 30pt>
<tr> <td> جيل عشوائي من الألوان
</r> <tr> <td> اضغط على زر البدء والصفوف الثلاثة للعجلات في البداية اليمنى للفة
</r> <tr> <td> اضغط على الأزرار الثلاثة X لتعيين قيمة اللون
</r> <tr> <td> اضغط على زر المعاينة لرؤية تأثير اللون
</r>
</table> <p>
</body>
</html>
آمل أن تكون هذه المقالة مفيدة لبرمجة JavaScript للجميع.