我这里有一个小代码,通过控制台日志,我可以看到它明显改变了,但在显示屏上它没有改变。出了什么问题?
下面是JS香草
const gameItem = document.querySelectorAll('.game-item');
const gameItemS = document.querySelector('.game-item');
document.addEventListener('DOMContentLoaded', () => {
titleSize(gameItem);
});
const titleSize = (gameItem) => {
[...gameItem].forEach((title) => {
let textSize = window
.getComputedStyle(title, null)
.getPropertyValue('font-size');
let gameTitle = title.innerText;
// console.log(gameTitle, gameTitle.length, textSize);
if (gameTitle.length > 7) {
textSize = '5px';
console.log(
'The font on this was changed: ' + gameTitle,
gameTitle.length,
textSize
);
}
});
};
下面的html
<section class="games">
<h1>Games</h1>
<ol class="container">
<li class="game-item">Halo<img src="" /></li>
<li class="game-item">Pokemon<img src="" /></li>
<li class="game-item">
Animal Crossing<img src="" />
</li>
<li class="game-item">Genshin Impact<img src="" /></li>
<li class="game-item">Skyrim<img src="" /></li>
</ol>
</section>