简体   繁体   English

在输入掩码货币中更改货币符号或将其删除

[英]Change the currency symbol or remove it in the inputmask currency

I'm using Robin Herbot's inputmask jquery plugin and I want to change the default currency symbol (by default, its a dollar currency symbol) to a PESO currency symbol or remove the currency symbol.我正在使用Robin Herbot 的 inputmask jquery 插件,我想将默认货币符号(默认情况下,它是美元货币符号)更改为比索货币符号或删除货币符号。

Below is what I've tried, yes the symbol changes and the symbol is removed but it won't let me type anything.下面是我尝试过的,是的,符号发生了变化,符号被删除了,但它不会让我输入任何内容。

 $(document).ready(function(){ $("#currency1").inputmask({ alias : "currency", mask : "0.00" }); $("#currency2").inputmask({ alias : "currency", mask : "₱ 0.00" }); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.2.6/jquery.inputmask.bundle.min.js"></script> <label>REMOVE CURRENCY SYMBOL</label><br> <input type="text" id="currency1" /><br> <label>CHANGE THE CURRENCY SYMBOL</label><br> <input type="text" id="currency2" />

You can change the symbol by using the prefix option.您可以使用prefix选项更改符号。 Below is a snippet where I do this in two different ways, modifying the currency alias and defining my own alias.下面是我以两种不同方式执行此操作的片段,修改货币别名和定义我自己的别名。

In your version you couldn't type anything since the mask property is used to restrict input and setting it to 0.00 only allows those four characters to be entered and nothing else.在您的版本中,您无法输入任何内容,因为mask属性用于限制输入并将其设置为0.00仅允许输入这四个字符而不允许输入其他字符。 A mask of 9.99 would allow a number followed by a period and two numbers. 9.99的掩码将允许一个数字后跟一个句点和两个数字。 9 has a special masking definition allowing any number. 9有一个特殊的掩码定义,允许任何数字。

 Inputmask.extendAliases({ pesos: { prefix: "₱ ", groupSeparator: ".", alias: "numeric", placeholder: "0", autoGroup: true, digits: 2, digitsOptional: false, clearMaskOnLostFocus: false } }); $(document).ready(function(){ $("#currency1").inputmask({ alias : "currency", prefix: '' }); $("#currency2").inputmask({ alias : "currency", prefix: '₱ ' }); $("#currency3").inputmask({ alias : "pesos" }); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.2.6/jquery.inputmask.bundle.min.js"></script> <label>REMOVE CURRENCY SYMBOL</label><br> <input type="text" id="currency1" /><br> <label>CHANGE THE CURRENCY SYMBOL</label><br> <input type="text" id="currency2" /><br> <label>CHANGE THE CURRENCY SYMBOL, using an alias</label><br> <input type="text" id="currency3" />

Solution with data-inputmask attribute具有 data-inputmask 属性的解决方案

 $(document).ready(function(){ $("input").inputmask(); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.2.6/jquery.inputmask.bundle.min.js"></script> <label>REMOVE CURRENCY SYMBOL</label><br> <input type="text" id="currency1" data-inputmask="'alias': 'decimal', 'groupSeparator': ',', 'autoGroup': true, 'digits': 2, 'digitsOptional': false, 'placeholder': '0'" style="text-align: right;"><br> <label>CHANGE THE CURRENCY SYMBOL</label><br> <input type="text" id="currency2" data-inputmask="'alias': 'decimal', 'groupSeparator': ',', 'autoGroup': true, 'digits': 2, 'digitsOptional': false, 'prefix': '₱ ', 'placeholder': '0'" style="text-align: right;">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM