加载中...

jQuery.fn.extend()


概述    jQuery.fn.extend( object )

返回值:jQuery

描述:一个对象的内容合并到jQuery的原型,以提供新的jQuery实例方法。

  • V : 1.0jQuery.fn.extend( object )

    • object
      Type: Object
      一个对象,用来合并到jQuery的原型。
jQuery.fn.extend()方法继承了jQuery原型($.fn)对象,以提供jQuery原型新的方法,可以链式调用jQuery()函数。

示例

实例

添加两个方法到jQuery原型($.fn),并且使用他们。

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery.fn.extend demo</title>
  6. <style>
  7. label { display: block; margin: .5em; }
  8. </style>
  9. <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  10. </head>
  11. <body>
  12. <label><input type="checkbox" name="foo"> Foo</label>
  13. <label><input type="checkbox" name="bar"> Bar</label>
  14. <script>
  15. jQuery.fn.extend({
  16. check: function() {
  17. return this.each(function() { this.checked = true; });
  18. },
  19. uncheck: function() {
  20. return this.each(function() { this.checked = false; });
  21. }
  22. });
  23. // Use the newly created .check() method
  24. $( "input[type='checkbox']" ).check();
  25. </script>
  26. </body>
  27. </html>

运行一下


还没有评论.