小白教程
所有教程
关于
Search
108.162.216.93
108.162.216.93
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Misc fn extend”的源代码
本页内容
上一节:
Misc_extend
下一节:
Misc_globaleval
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:$.fn.extend()}}[[Category:jquery ref misc|16]] = jQuery.fn.extend()方法 = [[jquery ref misc|jQuery 杂项方法]] 添加两个方法到jQuery原型($.fn) <sample title="" desc="" lang="html" hererun="1"> <label><input type="checkbox" name="foo"> Foo</label> <label><input type="checkbox" name="bar"> Bar</label> <script> $(function () { $.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> </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script> <style> label { display: block; margin: .5em; } </style> </head> <body> <label><input type="checkbox" name="foo"> Foo</label> <label><input type="checkbox" name="bar"> Bar</label> <script> $(function () { $.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> </run> == 定义和用法 == $.fn.extend() 函数为jQuery扩展一个或多个实例属性和方法(主要用于扩展方法)。 '''提示:'''jQuery.fn是jQuery的原型对象,其extend()方法用于为jQuery的原型添加新的属性和方法。这些方法可以在jQuery实例对象上调用。 == 语法 == $.fn.extend( object ) {| class="table table-striped table-hover" ! 参数 ! 描述 |- | object | Object类型 指定的对象,用来合并到jQuery的原型对象上。 |} [[jquery ref misc|jQuery 杂项方法]]
返回至“
Misc fn extend
”。
上一节:
Misc_extend
下一节:
Misc_globaleval