$&'); } return text; } } }); // 页面加载时获取默认的关键词并渲染数据 fetchDataAndRender(defaultKeyword); // 封装 Hits Init 函数,统计人气 function initHits() { if ($('.mac_hits').length === 0) { return; } var $that = $(".mac_hits"); $.ajax({ type: 'get', url: maccms.path + '/index.php/ajax/hits?mid=' + $that.attr("data-mid") + '&id=' + $that.attr("data-id") + '&type=update', timeout: 5000, dataType: 'json', error: function () { }, success: function (json) { if (json.code == 1) { $(".mac_hits").each(function (i) { $type = $(".mac_hits").eq(i).attr('data-type'); if ($type != 'insert') { $('.' + $type).html(eval('(json.data.' + $type + ')')); } }); } } }); } // 在页面加载时调用函数 $(document).ready(function () { initHits(); });