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