【发布时间】:2018-10-16 03:41:19
【问题描述】:
到目前为止,我已经尝试过了,如果我采用元素 id 是有效的,但如果我采用类名是无效的......
<!DOCTYPE html>
<html>
<body>
<p id="p1" class="theClass">Hello World!</p>
<p id="p2">Hello World!</p>
<script>
document.getElementById("p2").style.color = "blue";
document.getElementsByClassName("theClass").style.color = "blue";
document.getElementById("p2").style.fontSize = "larger";
</script>
<p>The paragraph above was changed by a script.</p>
</body>
</html>
这是输出:
【问题讨论】:
标签: javascript html css class