jquery如何调用自定义函数

来源:互联网 发布:oppo网络营销策划书 编辑:程序博客网 时间:2024/05/22 00:35

原地址 : http://bbs.it985.com/thread-6085-1-1.html

第一种普通调用

<!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.还有其它方法,请多指教!

0 0
原创粉丝点击