document ready function
. الآن دعونا نكتب أول بيان jQuery الخاص بي. تبدأ جميع وظائف jQuery بـ $
، يشار إليه عادةً dollar sign operator
، أو bling
. غالبًا ما يحدد jQuery عنصر HTML مع selector
، ثم يقوم بشيء لهذا العنصر. على سبيل المثال، دعونا جعل كل من لديك button
عناصر ترتد. ما عليك $("button").addClass("animated bounce");
إضافة هذا الرمز داخل الدالة الجاهزة للمستند: $("button").addClass("animated bounce");
لاحظ أننا قمنا بالفعل بتضمين مكتبة jQuery ومكتبة Animate.css في الخلفية حتى يمكنك استخدامها في المحرر. لذا فأنت تستخدم jQuery لتطبيق فئة bounce
Animate.css على عناصر button
. addClass()
لإعطاء الطبقات animated
bounce
إلى عناصر button
.
testString: 'assert($("button").hasClass("animated") && $("button").hasClass("bounce"), "Use the jQuery addClass()
function to give the classes animated
and bounce
to your button
elements.");'
- text: استخدم jQuery فقط لإضافة هذه الألوان إلى العنصر.
testString: 'assert(!code.match(/class.*animated/g), "Only use jQuery to add these colors to the element.");'
- text: يجب أن يكون رمز jQuery الخاص بك ضمن $(document).ready();
وظيفة.
testString: 'assert(code.match(/\$\(document\)\.ready\(function.*(\s|\n)*.*button.*.addClass.*\);/g), "Your jQuery code should be within the $(document).ready();
function.");'
```