Jquery.inputmask not working

大城市里の小女人 提交于 2020-01-13 11:32:24

问题


Trying to use Robin Herbots Inputmask module, and can't get it working. Looking at all the other similar posts, a common problem to make sure the docment.ready function has a call to inputmask(), but this looks good to me.

Scripts

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
<script src="/js/jquery.inputmask.js">
<script src="/js/mainReady-client.js">
<script src="/js/bootstrap.min.js">

mainReady-client.js

$(document).ready(function() {
  $(":input").inputmask();
});

HTML

<td>
  <input value="10" data-inputmask="'mask': '999'">
</td>

I've tried:

$(document).ready(function() {
  $("#currIN").inputmask("9999");
});

or (the real one I want - currency)...

$(document).ready(function() {
  $("#currIN").inputmask("'alias': 'numeric', 'groupSeparator': ',', 'autoGroup': true, 'digits': 2, 'digitsOptional': false, 'prefix': '$ ', 'placeholder': '0'");
});

and then:

<td>
  <input value="10" id="currIN">
</td>

It seems so simple yet nothing happens. It has to be the order that I load things, but it all looks good. Thanks for any help. Cheers.


回答1:


Try to use this inputmask script,

<script type='text/javascript' src="https://rawgit.com/RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>

Working example JSFIDDLE

<!DOCTYPE html>
<html>
<head>
  <script type='text/javascript' src='http://code.jquery.com/jquery-1.11.0.js'></script>
  <script type='text/javascript' src="https://rawgit.com/RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>

<script type='text/javascript'>
//<![CDATA[ 
  $(window).load(function(){
    $("#currIN").inputmask("9999");
  });
//]]> 
</script>
</head>
<body>
  <td>
  <input value="10" id="currIN">
</td>
</body>
</html>



回答2:


You can use this CDN-

https://cdnjs.cloudflare.com/ajax/libs/jquery.inputmask/3.1.60/inputmask/jquery.inputmask.js

A working demo is given here for you-

$("#piash").inputmask("A-999");
<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.1.60/inputmask/jquery.inputmask.js"></script>

<td>
  <input value="A-45" id="piash">
</td>



回答3:


While this question is old I believe I have found a solution for those with a similar problem. The noConflict() function fixed it.

<script type='text/javascript'>

    $j=jQuery.noConflict();

    $j(document).ready(function () {

        $j("#currIN").inputmask("9999");

    });
</script>


来源:https://stackoverflow.com/questions/28510610/jquery-inputmask-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!