我有這個代碼:
<script>
radius.style.setproperty('display');
</script>
<style>
.radius{
display: none;
}
</style>
<body>
<p id="radius"> Enter the radius</p>
</body>
我打算在這里做的是,默認情況下,該段落具有 display=none。我想在滿足某些特定條件時通過 JS 顯示這一段。但問題是使用上面的代碼,我無法完成我想要的。請建議應該做什么?
uj5u.com熱心網友回復:
首先你應該得到 dom,然后改變樣式 attr。像這樣的例子:
<html>
<body>
<p id="p2">Hello World!</p>
<script>
document.getElementById("p2").style.color = "blue";
</script>
</body>
</html>
uj5u.com熱心網友回復:
嘗試
<html>
<body>
<p id="radius"> Enter the radius</p>
<script>
let radius = document.getElementById("radius");
if(condition == true){
radius.style.display = "block";
}else{
radius.style.display = "none";
}
</script>
</body>
</html>
uj5u.com熱心網友回復:
您可以在 javascript中設定元素樣式
element.style.cssPropertyInCamelCase = 'value'
例子
const element = document.getElementById('id')
element.style.display = 'none'
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/484559.html
標籤:javascript html css
上一篇:如何根據問題顯示特定錯誤?
