运行结果尺寸: 300 x 150
x
 
<!DOCTYPE html>
<html>
<head>
<style>
.myClass::after {
  content: " But you already knew that.";
}
</style>
</head>
<body>
<h1>使用 JavaScript 更改内容属性</h1>
<p>您不能在特定元素上设置伪类样式,但您可以通过在 STYLE 部分(或样式表)中创建一个类并将该类添加到指定元素来获得相同的结果。</p>
<p>单击“试一试”按钮将类“myClass”添加到 DIV 元素:</p>
<button onclick="myFunction()">试一试</button>
<div id="myDIV">这是我的 DIV 元素。</div>
<script>
function myFunction() {
  document.getElementById("myDIV").className += " myClass";
}
</script>
</body>
</html>
×

报个问题: