继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

jquery自定义事件的使用

英明神武的牛
关注TA
已关注
手记 317
粉丝 30
获赞 175

  jquery自定义事件要用到2个方法

  1:bind(type,[data],fn);其中type是自定义事件类型(名称);data是可选参数,是自定义函数fn中第一个参数中的data属性,注意data是一个数组类型;fn是事件触发时执行的函数。

  2:trigger(type,[data]);其中type是自定义事件类型(名称);data是可选参数是自定义函数fn中第二个参数,注意这是一个数组类型。

  应用举例:

  

<!doctype html><html lang="zh"> <head> <meta charset="UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>Document</title> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="renderer" content="webkit|ie-comp|ie-stand"> <meta name="keywords" content=""> <meta name="description" itemprop="description" content=""> <meta name="protocol" content="1"> <meta itemprop="name" content="name"> <meta itemprop="image" content="http://9.url.cn/edu/img/logo_pc_rich.png"/> <link rel="dns-prefetch" href="http://7.url.cn"> <link rel="dns-prefetch" href="http://9.url.cn"> <link rel="dns-prefetch" href="http://8.url.cn"> <link rel="stylesheet" href="http://8.url.cn/edu/css/common.980ee.css"/> <link rel="stylesheet" href="http://8.url.cn/edu/css/index_refactor.90164.css"/> <link rel="shortcut icon" href="http://9.url.cn/edu/img/favicon.ico"/> </head> <body>		<div>				<p>						<input type="text" id="number01" value="0">&nbsp;&nbsp;+				</p>				<p>						<input type="text" id="number02" value="1">&nbsp;&nbsp;						<input type="button" id="ok" value="=">				</p>				<p>						<input type="text" id="result" value="1">&nbsp;&nbsp;										</p>							</div>	<script type="text/javascript" src="js/jquery.js"></script>	<script type="text/javascript">	<!--		$(window).bind("resultChange",function(event,a,b,c){			alert(a+":"+b+":"+c);		});		$("#result").change(function(){					var result=$(this).val();			if(result>0)				$(window).trigger("resultChange",[result,result,result]);					});		$("#ok").click(function(){			$("#result").val(($("#number01").val()-0)+($("#number02").val()-0));			$("#result").change();		});	//-->	</script> </body></html>


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP