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"> +
</p>
<p>
<input type="text" id="number02" value="1">
<input type="button" id="ok" value="=">
</p>
<p>
<input type="text" id="result" value="1">
</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>
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。