JQuery事件绑定

JQuery事件绑定

两种方法:

  1. HTML属性去掉on(如onclike改为click)
  2. bind事件(bind:捆绑)

这俩方法的参数都是“函数”——事件触发时执行的函数。

<head>
	<meta charset="utf-8" />
	<title>事件绑定</title>
	<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
	<script>
		$(function() {
			// 1.获取元素
			// 2.绑定事件,使用匿名函数
			$("#btn1").click(function() {
				console.log("click:" + this);
			});
			$("#btn2").bind("click", function() {
				console.log("bind click:" + this)
			});
		});
	</script>
</head>

<body>
	<input id="btn1" type="button" value="click事件" />
	<input id="btn2" type="button" value="bind事件" />
</body>
原文地址:https://www.cnblogs.com/tigerlion/p/11178579.html