微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何通过JavaScript向WordPress插件添加阶乘计算?

如何解决如何通过JavaScript向WordPress插件添加阶乘计算?

我想向Calculated Fields Form wordpress插件添加阶乘(n!)计算。我发现module_public.js(朝这个方向:wp-content \ plugins \ calculated-fields-form \ js \ modules \ 01_mathematical_logical \ public)包含用于数学运算的代码,但我添加了这些代码,但它们不起作用(我可以通过将代码添加到module_admin.js中来为析因按钮创建一个按钮,该按钮可以工作,但无法获得结果)。 谁能帮我? 我添加到module_public.js的209行的代码

    if(window.FAC == undefined)
    {
        window.FAC = window.fac = function ()
        {
            
         
        var ans=1; 
          
        for (var i = 2; i <= FAC; i++) 
            ans = ans * i; 
        return ans; 
        };
    } // End if window.FAC
    

module_public.js的原始代码

    fbuilderjQuery = ( typeof fbuilderjQuery != 'undefined' ) ? fbuilderjQuery : jQuery;
fbuilderjQuery[ 'fbuilder' ] = f

    builderjQuery[ 'fbuilder' ] || {};
    fbuilderjQuery[ 'fbuilder' ][ 'modules' ] = fbuilderjQuery[ 'fbuilder' ][ 'mo

dules' ] || {};

fbuilderjQuery[ 'fbuilder' ][ 'modules' ][ 'default' ] = {
'prefix' : '','callback'      : function()
{
    if(Number.prototype.LENGTH == undefined)
    {
        // Only LENGTH in uppercase to prevent a conflict with Lottie
        Number.prototype.LENGTH = function(){return this.valueOf().toString().length;};
    }

    function ROUNDx(operation,num,y)
    {
        if(y && y != 0)
        {
            var r  = operation(num/y)*y,p = (new String(y)).split('.');
            if(p.length == 2) r = PREC(r,p[1].length);
            return r;
        }
        else
        {
            return operation(num);
        }
    };

    if(window.ROUND == undefined)
    {
        window.ROUND = window.round = function(num,y)
        {
            if(y) return ROUNDx(Math.round,y);
            return ROUNDx(Math.round,num);
        }
    }

    if(window.FLOOR == undefined)
    {
        window.FLOOR = window.floor = function(num,y)
        {
            if(y) return ROUNDx(Math.floor,y);
            return ROUNDx(Math.floor,num);
        }
    }

    if(window.CEIL == undefined)
    {
        window.CEIL = window.ceil = function(num,y)
        {
            if(y) return ROUNDx(Math.ceil,y);
            return ROUNDx(Math.ceil,num);
        }
    }

    if(window.PREC == undefined)
    {
        window.PREC = window.prec = function (num,pr)
            {
                if('undefined' == typeof pr) pr = 0;
                if(/^\d+$/.test(pr) && $.isNumeric(num))
                {
                    var f = POW(10,pr);
                    num = ROUND(num*f)/f;
                    return num.toFixed(pr);
                }
                return num;
            };
    } // End if window.PREC

    if(window.CDATE == undefined)
    {
        window.CDATE = window.cdate = function ( num,format )
            {
                format = ( typeof format != 'undefined' ) ? format : ( ( typeof window.DATETIMEFORMAT != 'undefined' ) ? window.DATETIMEFORMAT : 'dd/mm/yyyy' );

                if(isFinite(num*1))
                {
                    num = Math.round(num*86400000);

                    var date = new Date(num),d = date.getDate(),m = date.getMonth()+1,y = date.getFullYear(),h = date.getHours(),i = date.getMinutes(),s = date.getSeconds(),a = '';

                    m = (m < 10) ? '0'+m : m;
                    d = (d < 10) ? '0'+d : d;

                    if( /a/.test( format ) )
                    {
                        a = ( h >= 12 ) ? 'pm' : 'am';
                        h = h % 12;
                        h = ( h == 0 ) ? 12: h;
                    }
                    h = (h < 10) ? '0'+h : h;
                    i = (i < 10) ? '0'+i : i;
                    s = (s < 10) ? '0'+s : s;

                    return format.replace( /y+/i,y)
                                 .replace( /m+/i,m)
                                 .replace( /d+/i,d)
                                 .replace( /h+/i,h)
                                 .replace( /i+/i,i)
                                 .replace( /s+/i,s)
                                 .replace( /a+/i,a);
                }
                return num;
            };
    } // End if window.CDATE

    if(window.SUM == undefined)
    {
        window.SUM = window.sum = function ()
        {
            var r = 0,t;
            for(var i in arguments)
            {
                if(Array.isArray(arguments[i])) r += SUM.apply(this,arguments[i]);
                else
                {
                    t = arguments[i]*1;
                    if(!isNaN(t)) r += t;
                }
            }
            return r;
        };
    } // End if window.SUM

    if(window.CONCATENATE == undefined)
    {
        window.CONCATENATE = window.concatenate = function ()
        {
            var r = '';
            for(var i in arguments)
                if(Array.isArray(arguments[i])) r += CONCATENATE.apply(this,arguments[i]);
                else r += (new String(arguments[i]));
            return r;
        };
    } // End if window.CONCATENATE

    if(window.AVERAGE == undefined)
    {
        window.AVERAGE = window.average = function ()
        {
            return SUM.apply(this,arguments)/arguments.length;
        };
    } // End if window.AVERAGE

    if(window.GCD == undefined)
    {
        window.GCD = window.gcd = function( a,b)
            {
                if ( ! b) return a;
                return GCD(b,a % b);
            };
    } // End if window.GCD
    
    if(window.LCM == undefined)
    {
        window.LCM = window.lcm = function( a,b)
            {
                return (!a || !b) ? 0 : ABS((a * b) / GCD(a,b));
            };
    } // End if window.LCM

    if(window.LOGAB == undefined)
    {
        window.LOGAB = window.logab = function( a,b)
            {
                return LOG(a)/LOG(b);
            };
    } // End if window.LOGAB

    var math_prop = ["LN10","PI","E","LOG10E","SQRT2","LOG2E","SQRT1_2","LN2","cos","pow","log","tan","sqrt","asin","abs","exp","atan2","atanh","random","acos","atan","sin"];

    for(var i = 0,h = math_prop.length; i < h; i++)
    {
        if( !window[ math_prop[ i ] ] )
        {
            window[ math_prop[ i ] ] = window[ math_prop[ i ].toupperCase() ] = Math[ math_prop[ i ] ];
        }
    }

    if(window.MIN == undefined)
    {
        window.MIN = window.min = function ()
        {
            var l = [];
            for(var i in arguments)
                var l = l.concat(arguments[i]);
            return Math.min.apply(this,l);
        };
    } // End if window.MIN

    if(window.MAX == undefined)
    {
        window.MAX = window.max = function ()
        {
            var l = [];
            for(var i in arguments)
                var l = l.concat(arguments[i]);
            return Math.max.apply(this,l);
        };
    } // End if window.MAX
    

    if(window.radians == undefined)
    {
        window.radians = window.radians = function(a){ return a*PI/180;};
    }

    if(window.degrees == undefined)
    {
        window.degrees = window.degrees = function(a){ return a*180/PI;};
    }

    fbuilderjQuery[ 'fbuilder' ][ 'extend_window' ]( fbuilderjQuery[ 'fbuilder' ][ 'modules' ][ 'default' ][ 'prefix' ],CF_LOGICAL );
},'validator' : function( v )
    {
        return ( typeof v == 'number' ) ? isFinite( v ) : ( typeof v != 'undefined' );
    }

    

};

解决方法

尝试在下面粘贴代码!

   fbuilderjQuery = ( typeof fbuilderjQuery != 'undefined' ) ? fbuilderjQuery : jQuery;
fbuilderjQuery[ 'fbuilder' ] = f

    builderjQuery[ 'fbuilder' ] || {};
    fbuilderjQuery[ 'fbuilder' ][ 'modules' ] = fbuilderjQuery[ 'fbuilder' ][ 'mo

dules' ] || {};

fbuilderjQuery[ 'fbuilder' ][ 'modules' ][ 'default' ] = {
'prefix' : '','callback'      : function()
{
    if(Number.prototype.LENGTH == undefined)
    {
        // Only LENGTH in uppercase to prevent a conflict with Lottie
        Number.prototype.LENGTH = function(){return this.valueOf().toString().length;};
    }

    function ROUNDx(operation,num,y)
    {
        if(y && y != 0)
        {
            var r  = operation(num/y)*y,p = (new String(y)).split('.');
            if(p.length == 2) r = PREC(r,p[1].length);
            return r;
        }
        else
        {
            return operation(num);
        }
    };

    if(window.ROUND == undefined)
    {
        window.ROUND = window.round = function(num,y)
        {
            if(y) return ROUNDx(Math.round,y);
            return ROUNDx(Math.round,num);
        }
    }

    if(window.FLOOR == undefined)
    {
        window.FLOOR = window.floor = function(num,y)
        {
            if(y) return ROUNDx(Math.floor,y);
            return ROUNDx(Math.floor,num);
        }
    }

    if(window.CEIL == undefined)
    {
        window.CEIL = window.ceil = function(num,y)
        {
            if(y) return ROUNDx(Math.ceil,y);
            return ROUNDx(Math.ceil,num);
        }
    }

    if(window.PREC == undefined)
    {
        window.PREC = window.prec = function (num,pr)
            {
                if('undefined' == typeof pr) pr = 0;
                if(/^\d+$/.test(pr) && $.isNumeric(num))
                {
                    var f = POW(10,pr);
                    num = ROUND(num*f)/f;
                    return num.toFixed(pr);
                }
                return num;
            };
    } // End if window.PREC

    if(window.CDATE == undefined)
    {
        window.CDATE = window.cdate = function ( num,format )
            {
                format = ( typeof format != 'undefined' ) ? format : ( ( typeof window.DATETIMEFORMAT != 'undefined' ) ? window.DATETIMEFORMAT : 'dd/mm/yyyy' );

                if(isFinite(num*1))
                {
                    num = Math.round(num*86400000);

                    var date = new Date(num),d = date.getDate(),m = date.getMonth()+1,y = date.getFullYear(),h = date.getHours(),i = date.getMinutes(),s = date.getSeconds(),a = '';

                    m = (m < 10) ? '0'+m : m;
                    d = (d < 10) ? '0'+d : d;

                    if( /a/.test( format ) )
                    {
                        a = ( h >= 12 ) ? 'pm' : 'am';
                        h = h % 12;
                        h = ( h == 0 ) ? 12: h;
                    }
                    h = (h < 10) ? '0'+h : h;
                    i = (i < 10) ? '0'+i : i;
                    s = (s < 10) ? '0'+s : s;

                    return format.replace( /y+/i,y)
                                 .replace( /m+/i,m)
                                 .replace( /d+/i,d)
                                 .replace( /h+/i,h)
                                 .replace( /i+/i,i)
                                 .replace( /s+/i,s)
                                 .replace( /a+/i,a);
                }
                return num;
            };
    } // End if window.CDATE

    if(window.SUM == undefined)
    {
        window.SUM = window.sum = function ()
        {
            var r = 0,t;
            for(var i in arguments)
            {
                if(Array.isArray(arguments[i])) r += SUM.apply(this,arguments[i]);
                else
                {
                    t = arguments[i]*1;
                    if(!isNaN(t)) r += t;
                }
            }
            return r;
        };
    } // End if window.SUM

    if(window.CONCATENATE == undefined)
    {
        window.CONCATENATE = window.concatenate = function ()
        {
            var r = '';
            for(var i in arguments)
                if(Array.isArray(arguments[i])) r += CONCATENATE.apply(this,arguments[i]);
                else r += (new String(arguments[i]));
            return r;
        };
    } // End if window.CONCATENATE

    if(window.AVERAGE == undefined)
    {
        window.AVERAGE = window.average = function ()
        {
            return SUM.apply(this,arguments)/arguments.length;
        };
    } // End if window.AVERAGE

    if(window.GCD == undefined)
    {
        window.GCD = window.gcd = function( a,b)
            {
                if ( ! b) return a;
                return GCD(b,a % b);
            };
    } // End if window.GCD
    
    if(window.LCM == undefined)
    {
        window.LCM = window.lcm = function( a,b)
            {
                return (!a || !b) ? 0 : ABS((a * b) / GCD(a,b));
            };
    } // End if window.LCM

    if(window.LOGAB == undefined)
    {
        window.LOGAB = window.logab = function( a,b)
            {
                return LOG(a)/LOG(b);
            };
    } // End if window.LOGAB

    var math_prop = ["LN10","PI","E","LOG10E","SQRT2","LOG2E","SQRT1_2","LN2","cos","pow","log","tan","sqrt","asin","abs","exp","atan2","atanh","random","acos","atan","sin"];

    for(var i = 0,h = math_prop.length; i < h; i++)
    {
        if( !window[ math_prop[ i ] ] )
        {
            window[ math_prop[ i ] ] = window[ math_prop[ i ].toUpperCase() ] = Math[ math_prop[ i ] ];
        }
    }

    if(window.MIN == undefined)
    {
        window.MIN = window.min = function ()
        {
            var l = [];
            for(var i in arguments)
                var l = l.concat(arguments[i]);
            return Math.min.apply(this,l);
        };
    } // End if window.MIN

    if(window.MAX == undefined)
    {
        window.MAX = window.max = function ()
        {
            var l = [];
            for(var i in arguments)
                var l = l.concat(arguments[i]);
            return Math.max.apply(this,l);
        };
    } // End if window.MAX
    
     if(window.FAC == undefined)
    {
        window.FAC = window.fac = function (num)
        {
        let sm=num;
          if(num == 0)
            return 1;
          else{
              for(let i=num-1; i>=1; i--){
                sm *= (num-i); 
                console.log(sm);
              }
          return sm;
    }
    
    if(window.RADIANS == undefined)
    {
        window.RADIANS = window.radians = function(a){ return a*PI/180;};
    }

    if(window.DEGREES == undefined)
    {
        window.DEGREES = window.degrees = function(a){ return a*180/PI;};
    }

    fbuilderjQuery[ 'fbuilder' ][ 'extend_window' ]( fbuilderjQuery[ 'fbuilder' ][ 'modules' ][ 'default' ][ 'prefix' ],CF_LOGICAL );
},'validator' : function( v )
    {
        return ( typeof v == 'number' ) ? isFinite( v ) : ( typeof v != 'undefined' );
    }

    
};

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。