链接点击计数器,并显示链接被点击了多少次

时间:2019-01-27 13:39:19

标签: php html

我想计算点击此链接时的点击次数。并且在example.com中显示“点击了多少次(数字)链接” 不使用mysql。如果没有更好的PHP,则javascript没问题

server (input, output) {

    # previous code 

    demographics <- reactive ({  ... some manipulations .... })

    # new mapping function

    map(unique(demographics()$category), ~ chartTableBoxUI(id = .x))

}

1 个答案:

答案 0 :(得分:0)

对于纯JS实现,您可以按以下方式使用localStorage

<html>
<script>
    function init() {
        let count = localStorage.getItem('counter');
        if(count === null){
            count = 0;
            localStorage.setItem('counter', count);
        }
        count = parseInt(count);
        updateCount(count);
    }
    function incrementCounter() {
        let count = parseInt(localStorage.getItem('counter'));
        count = count + 1;
        localStorage.setItem('counter', count);
        updateCount(count);
        return true;
    }
    function updateCount(count) {
        document.getElementById("count").innerHTML = "Clicked "+count+" times!";
    }
</script>
<body>
    <p id="count">-</p>
    <script type="text/javascript">
        init();
    </script>
    <a href="https://www.google.com" onclick="incrementCounter()">Google</a>
</body>