jquery.extend方法

时间:2022-11-06 11:21:20

jquery.extend()用来扩展jquery中方法,实现插件。

1、jQuery.extend函数详细用法!

扩展jQuery静态方法.

1$.extend({
2test:function(){alert('test函数')}
3})

用法: $.test()

2、jQuery.extend 函数详解

上述两个虽说叫详解,讲解都很简略,下面这篇好一点。

3、jQuery $.extend()用法总结

jQuery.extend(object);为扩展jQuery类本身.为类添加新的方法。 
jQuery.fn.extend(object);给jQuery对象添加方法。

<!DOCTYPE html>
<html> <head>
<meta charset="utf-8">
<title>test</title> </head> <body>
<h3 class="ye">默认</h3>
<h3 class="ye">默认</h3>
<h3 class="ye">默认</h3>
<h3 class="ye">默认</h3>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
jQuery.fn.myPlugin = function(options) {
$options = $.extend( {
html: "方法自带值",
css: {
"color": "red",
"font-size":"14px"
}},
options);
return $(this).css({
"color": $options.css.color, }).html($options.html);
} $('.ye').myPlugin({html:"新的内容",css:{"color":"green","font-size":"20px"}});
</script>
</body> </html>