Bootstrap TouchSpin + NumeralJS 使用语言环境 pt-br 不工作
Bootstrap TouchSpin + NumeralJS using locale pt-br is not working
我正在尝试使用 bootstrap touchspin
+ numeraljs
将我的货币输入位置设置为 pt-br
。
为此,我通过 NumeralJS
注册了自定义语言环境,因此当我使用创建 increment 和 decrement[=35 的语言环境时=] 函数无法正常工作。如果我使用语言环境 en
,这些功能将完美运行。
使用的javascript
代码如下:
(function(global, factory) {
if (typeof define === 'function' && define.amd) {
define(['../numeral'], factory);
} else if (typeof module === 'object' && module.exports) {
factory(require('../numeral'));
} else {
factory(global.numeral);
}
}(this, function(numeral) {
numeral.register('locale', 'pt-br', {
delimiters: {
thousands: '.',
decimal: ','
},
abbreviations: {
thousand: 'mil',
million: 'milhões',
billion: 'b',
trillion: 't'
},
ordinal: function(number) {
return 'º';
},
currency: {
symbol: 'R$'
}
});
}));
numeral.locale('pt-br');
$("input[name='demo_callback']").TouchSpin({
callback_before_calculation: function(v) {
return numeral(v).value();
},
callback_after_calculation: function(v) {
return numeral(v).format("[=11=],0.00");
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://use.fontawesome.com/releases/v5.0.8/css/all.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-touchspin/4.2.5/jquery.bootstrap-touchspin.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js"></script>
<input id="demo_callback" type="text" value="1.00" data-bts-min="-1" data-bts-max="1000000" data-bts-step=".01" data-bts-decimals="2" name="demo_callback" />
此致
感谢所有试图提供帮助的人,
我可以通过在发送之前将区域设置 en
的 小数分隔符 替换为区域设置 pt-br
的小数分隔符来解决问题通过 NumeralJS
:
进行转换
(function(global, factory) {
if (typeof define === 'function' && define.amd) {
define(['../numeral'], factory);
} else if (typeof module === 'object' && module.exports) {
factory(require('../numeral'));
} else {
factory(global.numeral);
}
}(this, function(numeral) {
numeral.register('locale', 'pt-br', {
delimiters: {
thousands: '.',
decimal: ','
},
abbreviations: {
thousand: 'mil',
million: 'milhões',
billion: 'b',
trillion: 't'
},
ordinal: function(number) {
return 'º';
},
currency: {
symbol: 'R$'
}
});
}));
numeral.locale('pt-br');
$("input[name='demo_callback']").TouchSpin({
callback_before_calculation: function(v) {
return numeral(v.replace('.', ',')).value();
},
callback_after_calculation: function(v) {
return numeral(v.replace('.', ',')).format("[=10=],0.00");
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://use.fontawesome.com/releases/v5.0.8/css/all.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-touchspin/4.2.5/jquery.bootstrap-touchspin.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js"></script>
<input id="demo_callback" type="text" value="1.00" data-bts-min="-1" data-bts-max="1000000" data-bts-step=".01" data-bts-decimals="2" name="demo_callback" />
我正在尝试使用 bootstrap touchspin
+ numeraljs
将我的货币输入位置设置为 pt-br
。
为此,我通过 NumeralJS
注册了自定义语言环境,因此当我使用创建 increment 和 decrement[=35 的语言环境时=] 函数无法正常工作。如果我使用语言环境 en
,这些功能将完美运行。
使用的javascript
代码如下:
(function(global, factory) {
if (typeof define === 'function' && define.amd) {
define(['../numeral'], factory);
} else if (typeof module === 'object' && module.exports) {
factory(require('../numeral'));
} else {
factory(global.numeral);
}
}(this, function(numeral) {
numeral.register('locale', 'pt-br', {
delimiters: {
thousands: '.',
decimal: ','
},
abbreviations: {
thousand: 'mil',
million: 'milhões',
billion: 'b',
trillion: 't'
},
ordinal: function(number) {
return 'º';
},
currency: {
symbol: 'R$'
}
});
}));
numeral.locale('pt-br');
$("input[name='demo_callback']").TouchSpin({
callback_before_calculation: function(v) {
return numeral(v).value();
},
callback_after_calculation: function(v) {
return numeral(v).format("[=11=],0.00");
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://use.fontawesome.com/releases/v5.0.8/css/all.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-touchspin/4.2.5/jquery.bootstrap-touchspin.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js"></script>
<input id="demo_callback" type="text" value="1.00" data-bts-min="-1" data-bts-max="1000000" data-bts-step=".01" data-bts-decimals="2" name="demo_callback" />
此致
感谢所有试图提供帮助的人,
我可以通过在发送之前将区域设置 en
的 小数分隔符 替换为区域设置 pt-br
的小数分隔符来解决问题通过 NumeralJS
:
(function(global, factory) {
if (typeof define === 'function' && define.amd) {
define(['../numeral'], factory);
} else if (typeof module === 'object' && module.exports) {
factory(require('../numeral'));
} else {
factory(global.numeral);
}
}(this, function(numeral) {
numeral.register('locale', 'pt-br', {
delimiters: {
thousands: '.',
decimal: ','
},
abbreviations: {
thousand: 'mil',
million: 'milhões',
billion: 'b',
trillion: 't'
},
ordinal: function(number) {
return 'º';
},
currency: {
symbol: 'R$'
}
});
}));
numeral.locale('pt-br');
$("input[name='demo_callback']").TouchSpin({
callback_before_calculation: function(v) {
return numeral(v.replace('.', ',')).value();
},
callback_after_calculation: function(v) {
return numeral(v.replace('.', ',')).format("[=10=],0.00");
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link href="https://use.fontawesome.com/releases/v5.0.8/css/all.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-touchspin/4.2.5/jquery.bootstrap-touchspin.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeral.js/2.0.6/numeral.min.js"></script>
<input id="demo_callback" type="text" value="1.00" data-bts-min="-1" data-bts-max="1000000" data-bts-step=".01" data-bts-decimals="2" name="demo_callback" />