转自:http://blog.csdn.net/happymagic/article/details/8517952
第一种普通调用
-
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>艾它社区</title>
- <script type="text/javascript" src="./jquery.js"></script>
- <script type="text/javascript">
- /*jquery函数*/
- function fun1(){
- $("div").css("color", "red");
- };
- $(document).ready(function(){
- /*jquery函数调用方式*/
- $("button").click(function(){
- fun1();
- });
- })
- </script>
- </head>
- <body>
- <button>点击我</button>
- <div>我会变红的哦</div>
- </body>
- </html>
复制代码
第二种jquery对象中的自定义函数
-
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>艾它社区</title>
- <script type="text/javascript" src="./jquery.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- /*jquery函数*/
- $.extend({'fun1':function(){
- $("div").css("color", "red");
- }});
- /*jquery函数调用方式*/
- $("button").click(function(){
- $.fun1();
- });
- })
- </script>
- </head>
- <body>
- <button>点击我</button>
- <div>我会变红的哦</div>
- </body>
- </html>
-
复制代码