Jquery 实现鼠标事件
编写代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="jquery\jquery.js"></script>
<style>
#div1 {
background-color: white;
margin: 20px;
width: 200px;
height: 200px;
border: pink 5px solid;
}
</style>
</head>
<body>
<!-- <a href="https://jquery.com">default click action is prevented</a>
<div id="log"></div>
<script>
$("a").click(function(event) {
event.preventDefault();
$('<div/>').append('default ' + event.type + ' prevented').appendTo('#log'); //default click prevented
});
</script> -->
<div id="div1"></div>
<script>
$(Document).ready(function() {
// alert("hello");
$("#div1").click(function() {
$(this).css("backgroundColor", "red");
})
$("#div1").hover(function() {
$(this).css("backgroundColor", "hotpink")
})
$("#div1").mouseout(function() {
$(this).css("backgroundColor", "white")
})
// $("div1").one("hover",function(){
// // alert(event.data.a)
// $(this).css("backgroundColor","hotpink")
})
</script>
</body>
</html>
运行结果