温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

jquery自定义事件的使用

发布时间:2020-07-05 13:58:33 来源:网络 阅读:355 作者:cmdlovehl 栏目:web开发

  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="p_w_picpath" content="https://cache.yisu.com/upload/information/20200311/55/213636.jpg"/>

 <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>


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI