小白教程
所有教程
关于
Search
172.70.127.103
172.70.127.103
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Misc jquery sub”的源代码
本页内容
上一节:
Misc_hasdata
下一节:
Misc_jquery_speed
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:$.sub()}}[[Category:jquery ref misc|41]] = jQuery jQuery.sub() 方法 = [[jquery ref misc|jQuery 杂项方法]] 添加一个方法到jQuery sub,以便它不会暴露在外 <sample title="" desc="" lang="html" hererun="1"> (function(){ var sub = jQuery.sub(); sub.fn.myCustomMethod = function(){ return 'just for me'; }; sub(document).ready(function() { alert(sub('body').myCustomMethod()); }); alert(typeof jQuery('body').myCustomMethod); //underfine })(); </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <script src="https://cdn.staticfile.org/jquery/1.6.2/jquery.min.js"></script> </head> <body> <script> (function(){ var sub = jQuery.sub(); sub.fn.myCustomMethod = function(){ return 'just for me'; }; sub(document).ready(function() { alert(sub('body').myCustomMethod()); }); alert(typeof jQuery('body').myCustomMethod); //underfine })(); </script> </body> </html> </run> == 定义和用法 == $.sub() 函数可创建一个新的jQuery副本,其属性和方法可以修改,而不会影响原来的jQuery对象。 '''注意:'''1. 从jQuery1.7开始已经过时,在jQuery 1.8版本将被移动到一个插件中。 2. $.sub() 并不尝试做任何形式的隔离。所有 jQuery 副本中的方法依然指向原始的 jQuery。(例如,依然会通过原始的 jQuery 进行事件绑 定和触发,data 也会通过原始的 jQuery 绑定到元素上。Ajax 请求和事件也是通过原始的 jQuery 运行的等等。) == 语法 == '''提示:'''该方法不接受任何参数。 $.sub() == 更多实例 == [[try.php?filename=tryjquery_sub1|重写一些 jQuery 方法]] 重写一些 jQuery 方法,提供新的功能。 [[try.php?filename=tryjquery_sub2|创建一个插件]] 创建一个插件,返回插件的具体方法。 [[jquery ref misc|jQuery 杂项方法]]
返回至“
Misc jquery sub
”。
上一节:
Misc_hasdata
下一节:
Misc_jquery_speed