总有人间一两风,填我十万八千梦

jQuery .fnextend() 用法 手册 | 示例代码

jQuery开发手册 归档 270℃ 0评论

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

  • version added: 1.0jQuery.fn.extend( object )

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

Example:

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

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

转载请注明:悠然品鉴 » jQuery .fnextend() 用法 手册 | 示例代码

喜欢 (0)or分享 (0)
发表我的评论
取消评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址