jQuery事件函数
jQuery 事件处理方法是 jQuery 中的核心函数。
事件处理程序指的是当 HTML 中发生某些事件时所调用的方法。术语由事件“触发”(或“激发”)经常会被使用。
通常会把 jQuery 代码放到 <head>部分的事件处理方法中:
<html>
<head>
<script type="text/javascript" src="jquery-3.6.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("h2").click(function(){
$(this).hide()
});
$('div').click(function(){
$(this).css('font-size','30px')
});
});
</script>
</head>
<body>
<h2>This is a heading</h2>
<div>This is a paragraph.</div>
<div>This is another paragraph.</div>
</body>
</html>上面实例,点击h2就会消失,点击任何一个div,字体都会变成30px;
点击前效果如下:

点击后效果如下:

下一篇: jQuery如何实现点击后隐藏或显示元素
上一篇:jQuery选择器实例表







评论