创建一个HTML页面,使用<script>标记直接引入jQuery文件;定义一个样式类current:宽200px,高100px,背景色粉色;定义一个div,使用jQuery获取div元素,并通过事件方法绑定click()事件,实现单击div时使用addClass()方法添加样式类current来设置div样式。
时间: 2023-12-03 12:46:32 浏览: 96
请参考以下代码实现:
```html
<!DOCTYPE html>
<html>
<head>
<title>jQuery Demo</title>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<style>
.current {
width: 200px;
height: 100px;
background-color: pink;
}
</style>
</head>
<body>
<div id="myDiv">Click me!</div>
<script>
$(document).ready(function(){
$("#myDiv").click(function(){
$(this).addClass("current");
});
});
</script>
</body>
</html>
```
在上面的示例中,我们使用了`<script>`标记直接引入了jQuery文件。然后,定义了一个样式类`.current`,并定义了一个`<div>`元素。在`<script>`标记中,我们使用了`$(document).ready()`方法来确保页面加载完成后再执行相关的代码。我们通过`$("#myDiv")`选择器获取到了`<div>`元素,并使用`.click()`方法绑定了`click`事件。当用户单击`<div>`元素时,我们使用`.addClass()`方法将样式类`.current`添加到`<div>`元素中,以设置其样式。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<html> <head> <title>人员管理界面</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js"></script> </head> <body> 员工列表 —— 显示所有员工信息 ID 姓名 电话号 地址 职位 职位编号 状态 证件照 <c:forEach items="${employees}" var="employees"> ${employees.id} ${employees.name} ${employees.phonenumber} ${employees.address} ${employees.job} ${employees.jobid} ${employees.state} ![]()
更改 | 删除 </c:forEach> </body> </html>给这个界面的表格实现一个分页的功能,每页的最大数目为5
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)