首页 > 解决方案 > 未捕获的类型错误:$.number 不是函数

问题描述

我正在尝试从 api 获取服务器统计信息。后端工作,但 javascript 方面没有。我收到这个错误。

Uncaught TypeError: $.number is not a function

.

 function getStats(auto=true) {
        var rStart = Date.now();
        if (window.rServerID == "home") {
            rURL = "<?php echo site_url('index.php/api/stats'); ?>";
        } else {
            rURL = "<?php echo site_url('index.php/api/stats/'); ?>" ;
        }
        $.getJSON(rURL, function(data) {
            
            // Open Connections
            var rCapacity = Math.ceil((data.open_connections / data.total_connections) * 100);
            if (isNaN(rCapacity)) { rCapacity = 0; }
            $(".active-connections .entry").html($.number(data.open_connections, 0));
            $(".active-connections .entry-percentage").html($.number(data.total_connections, 0));
            $(".active-connections .progress-bar").prop("aria-valuenow", rCapacity);
            $(".active-connections .progress-bar").css("width", rCapacity.toString() + "%");
            $(".active-connections .sr-only").html(rCapacity.toString() + "%");

标签: javascripthtmljquery

解决方案


我找到了解决方案。这个函数($.number)来自 jquery-number 库。 https://github.com/customd/jquery-number

谢谢你们 :)


推荐阅读