使用JavaScript/jQuery选择(突出显示)表中的所有文本可以通过以下步骤实现:
.css()
方法来设置样式,例如设置背景颜色为黄色:$('.highlightable').css('background-color', 'yellow');完整的代码示例如下:
<!DOCTYPE html>
<html>
<head>
<title>选择表中的所有文本</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
.highlightable {
background-color: yellow;
}
</style>
</head>
<body>
<table>
<tr>
<td class="highlightable">文本1</td>
<td class="highlightable">文本2</td>
<td class="highlightable">文本3</td>
</tr>
</table>
<script>
$(document).ready(function() {
$('.highlightable').css('background-color', 'yellow');
});
</script>
</body>
</html>
这样,使用JavaScript/jQuery选择(突出显示)表中的所有文本就完成了。当页面加载完成时,所有具有"highlightable"类名的文本元素将被突出显示为黄色背景。
领取专属 10元无门槛券
手把手带您无忧上云