为什么不能要求验证

时间:2017-05-07 16:52:16

标签: jquery validation gulp

我使用glup和插件laravel-elixir'包装js。
我的gulpfile.js代码是:

var elixir = require('laravel-elixir');
elixir(function(mix) {
    mix.browserify('app.js');
    mix.browserify('libs/jquery-validate.js','./public/js/libs/jquery-validate.js');
});

app.js代码是:

window.$ = window.jQuery = require('jquery');
// require('jquery-validation/dist/jquery.validate.js');
$(document).ready(function () {
});

jquery-validation.js代码是:

require('jquery-validation/dist/jquery.validate.js');
$("#form").validate({
  rules: {
     name: "required",
  },
  messages: {
     name: "name can't null",
  }
});

在身体的末尾,我使用这两个js:

<script src="/js/app.js"></script>
<script src="/js/libs/jquery-validation.js"></script>

但是当app.js中的require('jquery-validation/dist/jquery.validate.js')时,jquery-validation可以工作,但是如果它在jquery-validation.js中,那么consle会抛出错误:

jquery-validate.js:11842 Uncaught TypeError: $(...).validate is not a function
    at Object.3.jquery-validation/dist/jquery.validate.js (jquery-validate.js:11842)
    at s (jquery-validate.js:1)
    at e (jquery-validate.js:1)
    at jquery-validate.js:1

为什么require('jquery-validation/dist/jquery.validate.js')可以在jquery.validate.js中

0 个答案:

没有答案