JavaScript 参考手册
Style counterIncrement 属性
改变 counterIncrement 属性
源代码:
点击运行 »
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>蜜蜂教程(mifengjc.com)</title> <style> h1 { counter-increment: section; } h1:before { content: "第 " counter(section) " 部分:"; } </style> </head> <body> <h1>HTML 教程</h1> <h1 id="myH1">CSS 教程</h1> <h1>JavaScripts 教程</h1> <p>点击“尝试一下”按钮改变第二个 H1 元素的 counterIncrement:</p> <button onclick="myFunction()">尝试一下</button> <script> function myFunction() { document.getElementById("myH1").style.counterIncrement = "subsection"; } </script> </body> </html>
运行结果:
点击运行 »