保持一个连续的总数

Keep a running total

本文关键字:连续 一个      更新时间:2023-09-26

我的应用程序中有一个项目列表,上面有单选按钮。当我更改单选按钮上的设置时,我想更新页面底部的运行总数。如何设置运行总数?

这有一些缺陷,但它应该让你开始:

<html>
<head>
<script>
    var total = 0;
    function count(input) {
        if(input.checked) {
            total++;
        }
        document.getElementById('total').innerHTML = total;
    }
</script>
</head>
<body>
    <input type="radio" id="radio1" onclick="count(this);"/>Radio 1
    <span id="total">0</span>
</body>
</html>