Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQuery包含带有常量的文件_Jquery - Fatal编程技术网

JQuery包含带有常量的文件

JQuery包含带有常量的文件,jquery,Jquery,我有以下jQuery常量文件,它看起来像这样: function($) { var Constants = { DECIMAL_SEPARATOR: ",", .... } })(jQuery); $("$.financeTable input").numeric(Constants.DECIMAL_SEPARATOR); alert($.Constants.DECIMAL_SEPARATOR); 我正在引用HTML页面部分中的文件。 稍

我有以下jQuery常量文件,它看起来像这样:

function($) { 
    var Constants =     {
        DECIMAL_SEPARATOR: ",", 
    ....
    } })(jQuery);
$("$.financeTable input").numeric(Constants.DECIMAL_SEPARATOR);
alert($.Constants.DECIMAL_SEPARATOR);
我正在引用HTML页面部分中的文件。 稍后,我将在jQuery脚本调用中使用这些变量,如下所示:

function($) { 
    var Constants =     {
        DECIMAL_SEPARATOR: ",", 
    ....
    } })(jQuery);
$("$.financeTable input").numeric(Constants.DECIMAL_SEPARATOR);
alert($.Constants.DECIMAL_SEPARATOR);
当在元素中包含文件时,它不起作用,但当我将相同的代码复制到同一文件中的标记时,它起作用


怎么会这样?

可能是您在jQuery之前包含了该文件吗?

好的,我找到了,它必须是:

(function($) {

$.Constants = 
{
    DECIMAL_SEPARATOR: ",", 
    ...
    } })(jQuery);
使用方法如下:

function($) { 
    var Constants =     {
        DECIMAL_SEPARATOR: ",", 
    ....
    } })(jQuery);
$("$.financeTable input").numeric(Constants.DECIMAL_SEPARATOR);
alert($.Constants.DECIMAL_SEPARATOR);

不该脚本包含在JQuery脚本引用之后。