![](/img/trans.png)
[英]why font-weight is not working on some elements, and side questions
[英]Why the css font-weight property is not working in my case?
我的 selected_cell 只包含一個段落作為其子級,並應用了默認的普通類。
我的CSS代碼:
.normal{
font-weight: normal;
}.bold{
font-weight: bolder;
}
我的JS代碼:
function bold()
{
var selectedcell=document.querySelector('.selected-cell');
if(selectedcell.children[0].class=="normal")
{
selectedcell.children[0].class="bold";console.log(selectedcell.children[0])}
else
{
selectedcell.children[0].class="normal";console.log(selectedcell.children[0])};
}
在這里,我創建了一個粗體函數,其中我使用 font-weight 屬性使所選單元格的文本看起來更粗。但顯然它不起作用。
嘗試這個
function bold()
{
let selectedcell = document.querySelector('.selected-cell');
if(selectedcell.children[0].classList.contains("normal"))
{
selectedcell.children[0].classList.replace("normal","bold");
}
else
{
selectedcell.children[0].classList.add("normal");
};
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.