jquery如何调用自定义函数
2014-09-24 20:07
337 查看
原地址 : http://bbs.it985.com/thread-6085-1-1.html
第一种普通调用
第二种jquery对象中的自定义函数
注:
1.运行代码时,要有jquery.js文件,否则运行出错
2.还有其它方法,请多指教!
第一种普通调用
<!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函数*/ <strong><span style="color:#3333FF;">function fun1(){ $("div").css("color", "red"); }; $(document).ready(function(){ /*jquery函数调用方式*/ $("button").click(function(){ fun1(); }); })</span></strong> </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"> <strong><span style="color:#3333FF;">$(document).ready(function(){ /*jquery函数*/ $.extend({'fun1':function(){ $("div").css("color", "red"); }}); /*jquery函数调用方式*/ $("button").click(function(){ $.fun1(); }); })</span></strong> </script> </head> <body> <button>点击我</button> <div>我会变红的哦</div> </body> </html>
注:
1.运行代码时,要有jquery.js文件,否则运行出错
2.还有其它方法,请多指教!
相关文章推荐
- jquery如何调用自定义函数
- Response.Write 调用 JS文件中自定义的函数,jquery、js调用iframe父窗口与子窗口元素的方法
- 如何通过Hibernate调用oracle自定义函数
- 在JS中,一个自定义函数如何调用另一个自定义函数中的变量
- jquery调用自定义函数
- sqlserver存储过程如何调用自定义函数
- Jquery自定义一个带名称的、可以传参数的函数以及setTimeout延迟调用,用法详解
- 待补遗(4)[C]如何让编译器调用自定义函数而非同名库函数
- smarty里面如何调用自定义函数
- robot脚本__调用自定义函数
- [原创]如何在Delphi中调用.Net编写的DLL中的函数(Function)、过程(Procedure)
- [JavaScript]如何在服务端(Page.Write)调用自定义的JS方法
- Inside VCL:接口指针调用函数的时候,如何获得对象指针以完成函数调用?
- [原创]如何在Delphi中调用.Net编写的DLL中的函数(Function)、过程(Procedure)
- SQL Server 2005-如何在SQL Server用户自订函数中调用GetDate()函数
- 函数是如何被调用的?-探索代码背后的故事
- Inside VCL:接口指针调用函数的时候,如何获得对象指针以完成函数调用?
- 如何在Delphi中调用.Net编写的DLL中的函数(Function)、过程(Procedure)
- SQL Server 2005-如何在SQL Server用户自订函数中调用GetDate()函数
- 如何在VC中汇编,调用Nasm编写的函数