maskedinput未捕获TypeError:$(...)。mask不是函数

时间:2015-10-19 20:25:18

标签: javascript symfony maskedinput

下午好 我的就是

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="{{ asset('bundles/reflorestasite/js/jquery.maskedinput.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('bundles/reflorestasite/js/validacoes.js') }}"></script>
<script type="text/javascript" src="{{ asset_url }}"></script>

在“validacoes.js”文件中有

$(document).ready(function(){

  $(".cpf").mask("999.999.999-99");
  $('.cpf').blur(function () {
    var id=$(this).attr("id");
    var val=$(this).val();
    var pattern = new RegExp(/[0-9]{3}[\.]?[0-9]{3}[\.]?[0-9]{3}[-]?[0-9]{2}/);

    if(val.match(pattern) == null){
      $("#"+id+"_error").html("Digite um CPF válido");
    }
  });
});

我已经在控制台验证了所有的javascript文件。但是我收到错误“Uncaught TypeError:$(...)。mask不是函数”

有没有人知道为什么symfony没有识别出maskedinput插件?

非常感谢。

3 个答案:

答案 0 :(得分:12)

更改此行
$(document).ready(function($){

    resp.writeHead(code, {
      "Content-Type": mime.lookup(path),
      "Content-Length": stats.size,
      "Cache-Control": "public, max-age=3672000",
      // Write file last modified header
      "Last-Modified": stats.mtime.toUTCString()
    });

答案 1 :(得分:1)

我也遇到了同样的错误,但在我的情况下我忘了导入maskedinput.min.js

<script src="/js/jquery.maskedinput.min.js" type="text/javascript"></script>

我正在谷歌寻找解决方案哈哈。

答案 2 :(得分:1)

我解决了我的问题,我不得不删除重复的脚本连接

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.maskedinput-1.3.min.js"></script>