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

javascript - jQuery mask input without changing value - Stack Overflow

programmeradmin5浏览0评论

I am using masked-input-plugin but it changes value and field bees invalid ...

in my js

$phoneInput.mask('99-99-99-999');

and later in browser console

('.phone-input-order-form').val()
"99-99-99-999"

Is there any way to get from val "999999999" while it masked ?

I am thinking to extend jQuery val but maybe you know better way? maybe without this plugin? :D

I am using masked-input-plugin but it changes value and field bees invalid ...

in my js

$phoneInput.mask('99-99-99-999');

and later in browser console

('.phone-input-order-form').val()
"99-99-99-999"

Is there any way to get from val "999999999" while it masked ?

I am thinking to extend jQuery val but maybe you know better way? maybe without this plugin? :D

Share Improve this question edited Jul 8, 2015 at 10:18 madzohan asked Jul 8, 2015 at 10:14 madzohanmadzohan 11.8k9 gold badges42 silver badges68 bronze badges 8
  • possible duplicate of Remove literals from input mask after form submit? – stevenw00 Commented Jul 8, 2015 at 10:20
  • So basically you want to void doing that every single time? – briosheje Commented Jul 8, 2015 at 10:21
  • seems I asked clearly - 1) or extend val; 2) or somehow show mask without affect to inputs value – madzohan Commented Jul 8, 2015 at 10:23
  • @stevenw00 nope, It's not DRY There are many lines of code where I should add condition and put unmask or replace or whatever ... – madzohan Commented Jul 8, 2015 at 10:28
  • what about a newer prototype so that you won't need to extend .val()? do you have to replace that .val() so many times? something like that? jsfiddle/jvr0nqz2 – briosheje Commented Jul 8, 2015 at 10:32
 |  Show 3 more ments

3 Answers 3

Reset to default 3

Overriding jQuery's val() function might cause unexpected issues with other scripts. Maybe try something like this:

$.fn.maskVal = function () {
    return $(this).mask();
};

Demo: http://jsfiddle/alan0xd7/w4s0v7y3/

$('.phone-input-order-form').mask(); => "999999999"

do something like

yourstring.replace("-", ""); 
发布评论

评论列表(0)

  1. 暂无评论