最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Unmasked jQuery masked-Money - Stack Overflow

programmeradmin5浏览0评论

I use jQuery to currency my data for this page Masked-Money, and I want to use 'unmasked' because in my model I have decimal, and mas are not allowed in decimal values.

When I use without 'unmasked' it works well:

 <script>
    $(function () {
        $('#Total').maskMoney();
    })
</script>

but If I use unmasked, plugin doesn't works

<script>
    $(function () {
        $('#Total').maskMoney('unmasked');
    })
</script>

What I'm doing wrong, or what can I do to delete ma when I post

I use jQuery to currency my data for this page Masked-Money, and I want to use 'unmasked' because in my model I have decimal, and mas are not allowed in decimal values.

When I use without 'unmasked' it works well:

 <script>
    $(function () {
        $('#Total').maskMoney();
    })
</script>

but If I use unmasked, plugin doesn't works

<script>
    $(function () {
        $('#Total').maskMoney('unmasked');
    })
</script>

What I'm doing wrong, or what can I do to delete ma when I post

Share Improve this question asked Nov 6, 2015 at 0:34 GerryGerry 611 silver badge4 bronze badges 1
  • No familiar with that plugin, but you either need to create a custom model binder so that the value can be bound to your property, or you need to intercept the forms .submit() event and update the value of the hidden input so its submitted with the 'unmasked' value - e.g. $('form').submit(function() { var t = $('#Total').maskMoney('unmasked'); $('#Total').val(t); }); – user3559349 Commented Nov 6, 2015 at 1:20
Add a ment  | 

3 Answers 3

Reset to default 3

Looking at the demo page, you have two options:

  1. Provide some setup to the plugin

    $('#Total').maskMoney({thousands:''});

  2. Set some data properties on your input

    @Html.TextboxFor(m => m.Total, new { data_thousands=""})

Update.

Apologies, got the wrong end of the stick.

You would need to tie onto the submit event as stephen says and change the value to the correct version. something like this.

$(function(){
    $("form").submit(function() {
        $('#Total').val($('#Total').maskMoney('unmasked')[0]);
    });
});

That really worked for me:

  $("#form-id").submit(function(){
    var value = $('#input-value-id').maskMoney('unmasked')[0];
    $('#input-value-id').val(value);
  });

i have many input in a single form That's why i used the following codes

$('.field').maskMoney('destroy');
$('.field').maskMoney({thousands:'', decimal:'.'});
$('.field').maskMoney('mask');
发布评论

评论列表(0)

  1. 暂无评论