jQuery.inputmask和它的占位符

huangapple go评论52阅读模式
英文:

jQuery.inputmask and its placeholder

问题

以下是要翻译的代码部分:

$("input").inputmask("decimal", {
    "radixPoint": ",",
    "groupSeparator": " ",
    "digits": 2,
    "autoGroup": true,
    "digitsOptional": true,
    "suffix": " EUR",
    "placeholder": "129,5",
    "clearMaskOnLostFocus": false,
})

不好意思,这部分内容已经被您提供的代码本身包含,没有需要额外翻译的内容。

英文:

Here is my code:

                        $("input").inputmask("decimal", {
                            "radixPoint": ",",
                            "groupSeparator": " ",
                            "digits": 2,
                            "autoGroup": true,
                            "digitsOptional": true,
                            "suffix": " EUR",
                            "placeholder": "129,5",
                            "clearMaskOnLostFocus": false,
                        })

Everything works great but I don't really understand how to display "129,5" as a placeholder instead of "1"?

Thanks in advance for your help!

I tried to search within StackOverflow and read the official documentation for jQuery.inputmask, but it didn't help.

答案1

得分: 1

以下是翻译好的部分:

文档中的输入掩码插件包含了有关设置初始值的部分。

它指出你只需设置输入的value属性。

你可以在HTML中这样做,例如:<input value="129,5">

或者,你也可以使用jQuery来实现:

$(function () {
  $("input")
    .val("129,5")
    .inputmask("decimal", {
      "radixPoint": ",",
      "groupSeparator": " ",
      "digits": 2,
      "autoGroup": true,
      "digitsOptional": true,
      "suffix": " EUR",
      "clearMaskOnLostFocus": false,
    });
});
英文:

The docs for the inputmask plugin contain a section on Setting Initial Values.

It states that you just need to set the value attribute of the input.

You could do this in HTML, ex: <input value="129,5">

Alternatively, you could do it with jQuery:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

$(function () {
  $(&quot;input&quot;)
    .val(&quot;129,5&quot;)
    .inputmask(&quot;decimal&quot;, {
      &quot;radixPoint&quot;: &quot;,&quot;,
      &quot;groupSeparator&quot;: &quot; &quot;,
      &quot;digits&quot;: 2,
      &quot;autoGroup&quot;: true,
      &quot;digitsOptional&quot;: true,
      &quot;suffix&quot;: &quot; EUR&quot;,
      &quot;clearMaskOnLostFocus&quot;: false,
    });
});

<!-- language: lang-html -->

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/inputmask@5.0.8/dist/jquery.inputmask.min.js&quot;&gt;&lt;/script&gt;
&lt;input&gt;

<!-- end snippet -->

答案2

得分: 0

我查看了 jQuery.inputmask 的源代码,并了解到没有办法处理它,所以我不得不寻找不同的方法。

英文:

I looked through jQuery.inputmask source codes and understood that there's nothing to do about it so I had to find out different approach.

huangapple
  • 本文由 发表于 2023年4月11日 10:32:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75982008.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定