التابع ‎‎jQuery.fn.extend()‎‎ في jQuery

من موسوعة حسوب
< jQuery‏ | jQuery
اذهب إلى التنقل اذهب إلى البحث
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

jQuery.fn.extend( object )‎

القيم المعادة

يعيد كائنًا من النوع Object.

الوصف

يدمج هذا التابع محتويات كائنٍ مع الكائن prototype في jQuery لتوفير نسخةٍ جديدةٍ من توابع jQuery.

jQuery.fn.extend( object )‎

أُضيف مع الإصدار: 1.0.

object

الكائن المراد دمجه مع الكائن prototype في jQuery.

يوسِّع التابع jQuery.fn.extend()‎ الكائن prototype في ‎($.fn) jQuery لتوفير توابع جديدة يمكن ربطها (chain) بالدالة jQuery()‎.

أمثلة

إضافة تابعان جديدان إلى الكائن prototype في ‎($.fn) jQuery ثمَّ استعمال أحدهما:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery.fn.extend مثالٌ عن استعمال التابع</title>
  <style>
  label {
    display: block;
    margin: .5em;
  }
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<label><input type="checkbox" name="foo"> إنجاز المهمة الأولى</label>
<label><input type="checkbox" name="bar"> إنجاز المهمة الثانية</label>
 
<script>
jQuery.fn.extend({
  check: function() {
    return this.each(function() {
      this.checked = true;
    });
  },
  uncheck: function() {
    return this.each(function() {
      this.checked = false;
    });
  }
});
 
// المنشأ حديثًا .check() استعمال التابع
$( "input[type='checkbox']" ).check();
</script>
 
</body>
</html>

مصادر