我正在使用以下代码设置font-weight属性:
$(this).css({ 'font-weight': 'normal' });
现在我想检查一个元素是否具有粗体或正常的font-weight propety,我该怎么做?
答案 0 :(得分:12)
你可以使用:
fontWeight = $(this).css('font-weight')
比较:
if (fontWeight == 'normal'|| fontWeight == '400')
//or
if (fontWeight == 'bold' || fontWeight == '700')
答案 1 :(得分:2)
您可以使用:
if ($('#yourElement').css('font-weight') == 'normal') {
// Your code if font-weight is normal
} else if($('#yourElement').css('font-weight') == 'bold') {
// Your code if font-weight is bold
}