如何使用 JavaScript 创建或重置计数器?
要创建计数器,请在 JavaScript 中使用 counterReset 属性。你可以尝试运行以下代码,以使用 JavaScript 创建或重置一个或多个计数器 -
示例
<!DOCTYPE html>
<html>
<head>
<style>
h2:before {
counter-increment: section;
content: counter(section) " Quiz ";
}
</style>
</head>
<body>
<h1>Quizzes</h1>
<p>Change the counterIncrement</p>
<h2>Ruby</h2>
<h2 id="myID">Java</h2>
<h2>PHP</h2>
<h2>Perl</h2>
<button onclick="display()">Reset Counter</button>
<script>
function display() {
document.body.style.counterReset = "section";
}
</script>
</body>
</html>
Advertisements
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP