<script> var APP_ID = 'xxxxx'; var APP_KEY = 'xxxxx'; AV.init({ appId: APP_ID, appKey: APP_KEY }); // 显示次数 function showTime(Counter) { var query = new AV.Query("Counter"); if($(".leancloud_visitors").length > 0){ var url = $(".leancloud_visitors").attr('id').trim(); // where field query.equalTo("words", url); // count query.count().then(function (number) { // There are number instances of MyClass where words equals url. $(document.getElementById(url)).text(number? number : '--'); }, function (error) { // error is an instance of AVError. }); } } // 追加pv function addCount(Counter) { var url = $(".leancloud_visitors").length > 0 ? $(".leancloud_visitors").attr('id').trim() : 'icafebolger.com'; var Counter = AV.Object.extend("Counter"); var query = new Counter; query.save({ words: url }).then(function (object) { }) } $(function () { var Counter = AV.Object.extend("Counter"); addCount(Counter); showTime(Counter); }); </script>