jQuery.fn.extend()| jqueryAPI 2.2 中文手册- AspRain.cn 致力于Web开发技术翻译整理
From jQuery API 2.2.0
jQuery.fn.extend()
分类:实用工具
返回: Object
jQuery.fn.extend( object )
描述:把一个对象的内容合并到jQuery原型中,以提供一个新的jQuery实例方法。
该
jQuery.fn.extend()方法扩展了jQuery原型($.fn)对象,以提供新的方法,可以连缀到jQuery函数上。示例
向jQuery原型($.fn)对象添加两个方法,然后使用其中一个。
<!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.10.2.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>
演示结果
如果网页上不能运行示例,请点击http://www.asprain.cn/jQueryAPI/jquery.fn.extend.htm查看示例。
如果你觉得本文档对你有用,欢迎给翻译作者支付宝打赏,支持翻译作者源源不断翻译更多有用的技术文档。