javascript - 在 javascript 中更改 CSSOM css 样式属性
问题描述
我正在尝试使用 style.cssText 来显示使用 javascript 的隐藏段落。这是我的代码:
html:
<p class="toy-pictures-latest">Latest Toy Pictures</p>
<p class="toy-pictures-greatest">Greatest Toy Pictures</p>
CSS:
.toy-pictures-latest{
display: none;
}
.toy-pictures-greatest{
display: none;
}
js:
toy-pictures-latest.style.cssText = 'display: inline;';
我也试过
document.getElementById("toy-pictures-latest").style.cssText = 'display: inline;';
请参阅代码笔: Codepen
请让我知道我应该如何解决这个问题。
解决方案
js:
document.getElementById("toy-pictures-latest").style.display = "inline";
html:
<p id="toy-pictures-latest">Latest Toy Pictures</p>
CSS:
#toy-pictures-latest{
display: none;
}
推荐阅读
- javascript - TypeError:无法读取未定义的属性“属性”
- javascript - 如何用动态内容填充 Vue JS + Bootstrap 应用程序中的背景图像?
- javascript - Javascript存储在数组中
- angular - Add Google Maps API to Angular project as a component
- c - 在 Notepad++ 中使用正则表达式 (RegEx) 切换字符串位置
- javascript - 将多个对象传递到数组中
- python - 使用python pandas从excel中过滤数据
- python - 无法理解我的 str.translate 行的原因
- tensorflow - Blas GEMM 启动失败:Windows 上的 Tensorflow / Jupyter / Anaconda:
- r - model.frame.default 中的错误(form = classvariable ~ ., data = trainingDataset, : variable lengths different (found for 'Sepal.Length')