jQuery是一个快速、简洁的JavaScript库,它简化了HTML文档遍历、事件处理、动画和AJAX交互。jQuery Table特效可以通过jQuery插件实现,这些插件能够增强表格的视觉效果和交互性。
一个简单的jQuery表格悬停效果的示例代码如下:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
padding: 15px;
text-align: left;
}
tr:hover {background-color: #f5f5f5;}
</style>
<script>
$(document).ready(function(){
$("table tr").hover(
function(){
$(this).css("background-color", "#f5f5f5");
},
function(){
$(this).css("background-color", "");
}
);
});
</script>
</head>
<body>
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>Country</th>
</tr>
<tr>
<td>John</td>
<td>25</td>
<td>USA</td>
</tr>
<tr>
<td>Jane</td>
<td>24</td>
<td>UK</td>
</tr>
</table>
</body>
</html>
在这个示例中,当鼠标悬停在表格的行上时,该行的背景颜色会变为浅灰色,移开鼠标后颜色恢复。
通过上述代码和插件,可以大大提升网页中数据表格的视觉效果和用户体验。
领取专属 10元无门槛券
手把手带您无忧上云