渚漪Day09——web前端入门【jQuery入门】
jQuery
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.bootcss.com/jquery/3.5.0/jquery.js"></script>
</head>
<body>
<a href="#" id="test-jquery">点我</a>
<script>
$('#test-jquery').click(function () {
alert('hello,jQuery');
})
</script>
</body>
</html>
公式 $(selector).action()
事件监听
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.bootcss.com/jquery/3.5.0/jquery.js"></script>
<style>
#divMove{
height: 500px;
width: 400px;
border: 1px solid red;
}
</style>
</head>
<body>
mouse:<span id="mouseMove"></span>
<div id="divMove">
在这里移动鼠标
</div>
<script>
$(function () {
$('#divMove').mousemove(function (event) {
$('#mouseMove').text('x:'+(event.pageX-8)+',y:'+(event.pageY-30));
})
})
</script>
</body>
</html>