如何在 JQuery 中设置文本样式?

use*_*463 3 html css jquery text styling

我想让文本的一部分变得粗体并且比文本的其他部分更大。但目前我使用的 jquery 所有文本的大小、字体粗细和颜色都是相同的。例如,从下面的代码的第一部分开始,我希望出现“硬盘驱动器:辅助存储设备”。我希望硬盘驱动器和标题采用粗体。我想要另一半正常字体粗细更小。如何使用我拥有的代码在 jquery 或 css 中设置样式?:)

如果您能提供帮助,我们将不胜感激!

这是我的 j 查询:

$('#harddrive').hover(function() {
$('#info').text('Hard drive: Secondary Storage Device');
}, function() {
$('#info').text('');
});

$('#cd').hover(function() {
$('#info').text('CD: External Secondary Storage Device');
}, function() {
$('#info').text('');
});

$('#fan').hover(function() {
$('#info').text('Fan: Used to keep the computer cool');
}, function() {
$('#info').text('');
});

$('#powerblock').hover(function() {
$('#info').text('Power Block: Provides power to the computer');
}, function() {
$('#info').text('');
});
Run Code Online (Sandbox Code Playgroud)

imb*_*aby 5

如果您想设置文本样式,请使用.html()而不是。.text()

这是一个例子:

$('#harddrive').hover(function() {
$('#info').html('<h3><b>Hard drive:</b></h3> Secondary Storage Device');
}, function() {
$('#info').html('');
});
Run Code Online (Sandbox Code Playgroud)