jQuery选择器
$("p")
jQuery 元素选择器基于元素名选取元素。
$("#test")
jQuery #id 选择器通过 HTML 元素的 id 属性选取指定的元素。
页面中元素的 id 应该是唯一的,所以您要在页面中选取唯一的元素需要通过 #id 选择器。
$(".test")
jQuery 类选择器可以通过指定的 class 查找元素。
$("*")
选取所有元素
$(this)
选取当前 HTML 元素
$("p.intro")
选取 class 为 intro 的 <p> 元素
$("p:first")
选取第一个 <p> 元素
$("ul li:first")
选取第一个 <ul> 元素的第一个 <li> 元素
$("ul li:first-child")
选取每个 <ul> 元素的第一个 <li> 元素
$("[href]")
选取带有 href 属性的元素
$("a[target='_blank']")
选取所有 target 属性值等于 "_blank" 的 <a> 元素
$("a[target!='_blank']")
选取所有 target 属性值不等于 "_blank" 的 <a> 元素
$(":button")
选取所有 type="button" 的 <input> 元素 和 <button> 元素
$("tr:even")
选取偶数位置的 <tr> 元素
$("tr:odd")
选取奇数位置的 <tr> 元素
jQuery事件
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>点击事件</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</script>
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p>Reset点击消失P1</p>
<p>Reset点击消失P2</p>
<p>Reset点击消失P3</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>双击元素事件</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</script>
<script>
$(document).ready(function(){
$("p").dblclick(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p>Reset双击消失P1</p>
<p>Reset双击消失P2</p>
<p>Reset双击消失P3</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>鼠标穿过元素事件</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</script>
<script>
$(document).ready(function(){
$("p").mouseenter(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p>Reset鼠标穿过消失P1</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>鼠标移出元素事件</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</script>
<script>
$(document).ready(function(){
$("p").mouseleave(function(){
$(this).hide();
});
});
</script>
</head>
<body>
<p>Reset鼠标移出消失P1</p>
</body>
</html>
- 事件可以结合使用如下,鼠标移入移出事件结合使用案例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>鼠标移入移出元素事件</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</script>
<script>
$(document).ready(function(){
$("p").mouseenter(function(){
$(this).hide(1000);
});
$("p").mouseleave(function(){
$(this).show(1000);
});
});
</script>
</head>
<body>
<p>Reset鼠标移入消失,移出显示P1</p>
</body>
</html>