容易出错的代码随机开始工作,但在刷新后再次破坏

我正在尝试安装“selectize-rails”gem。 我遇到了很多麻烦( TypeError:$(…)。selectize不是一个函数 )所以我放弃了一段时间并且处理不相关的事情。 然后我回到它,gem突然工作,虽然我改变的代码都没有与它相关。 然后,我更改了一行代码并刷新了页面以查看结果,并再次在之前的Web控制台中显示相同的错误:

TypeError: $(...).selectize is not a function 

之后,这就是我所做的一切:1)在文本编辑器中按“返回”以恢复更改,2)保存文档,3)刷新页面。 并且,错误仍然存​​在,尽管完全相同的代码仅在几秒钟前工作。

有谁知道这有可能吗?

这是不起作用的代码块,然后突然开始工作,然后再次停止:

  $(document).ready(function() { console.log( typeof $.fn.selectize === 'function'); // true console.log( $('#select-to').length === 1 ); // true var REGEX_EMAIL = '([a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@' + '(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)'; $('#select-to').selectize({ persist: false, maxItems: null, valueField: 'email', labelField: 'name', searchField: ['name', 'email'], options: [ {email: 'brian@thirdroute.com', name: 'Brian Reavis'}, {email: 'nikola@tesla.com', name: 'Nikola Tesla'}, {email: 'someone@gmail.com'} ], render: { item: function(item, escape) { return '
' + (item.name ? '' + escape(item.name) + '' : '') + (item.email ? '' : '') + '
'; }, option: function(item, escape) { var label = item.name || item.email; var caption = item.name ? item.email : null; return '
' + '' + escape(label) + '' + (caption ? '' + escape(caption) + '' : '') + '
'; } }, createFilter: function(input) { var match, regex; // email@address.com regex = new RegExp('^' + REGEX_EMAIL + '$', 'i'); match = input.match(regex); if (match) return !this.options.hasOwnProperty(match[0]); // name regex = new RegExp('^([^<]*)\$', 'i'); match = input.match(regex); if (match) return !this.options.hasOwnProperty(match[2]); return false; }, create: function(input) { if ((new RegExp('^' + REGEX_EMAIL + '$', 'i')).test(input)) { return {email: input}; } var match = input.match(new RegExp('^([^<]*)\$', 'i')); if (match) { return { email : match[2], name : $.trim(match[1]) }; } alert('Invalid email address.'); return false; } }); });

我更改了这一行:

 {email: 'someone@gmail.com'} 

对此:

 {email: ''} 

然后回来。