Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我';我在select2上有此javascript异常:未捕获类型错误:无法读取属性';hasClass';空值?_Javascript_Jquery_Angularjs_Jquery Select2_Angularjs Select2 - Fatal编程技术网

为什么我';我在select2上有此javascript异常:未捕获类型错误:无法读取属性';hasClass';空值?

为什么我';我在select2上有此javascript异常:未捕获类型错误:无法读取属性';hasClass';空值?,javascript,jquery,angularjs,jquery-select2,angularjs-select2,Javascript,Jquery,Angularjs,Jquery Select2,Angularjs Select2,我在一个使用AngularJSV1.2.10(以及Java、SpringMVC、JPA等)的项目中。我们有一些Select2选择器工作正常,但有时javascript控制台输出以下错误: > Uncaught TypeError: Cannot read property 'hasClass' of null clazz.opened @ select2.js?rld=1.2.0-B2:1187 (anonymous function) @ select2.js?rld=1.2.

我在一个使用AngularJSV1.2.10(以及Java、SpringMVC、JPA等)的项目中。我们有一些Select2选择器工作正常,但有时javascript控制台输出以下错误:

> Uncaught TypeError: Cannot read property 'hasClass' of null
  clazz.opened @ select2.js?rld=1.2.0-B2:1187 
  (anonymous function) @ select2.js?rld=1.2.0-B2:1401
  n.event.dispatch @ jquery.min.js?rld=1.2.0-B2:3
  n.event.add.r.handle @ jquery.min.js?rld=1.2.0-B2:3
例如,我们的Select2声明之一是:

  ## Municipality
  <div class="col-md-6">
    <div class="form-group">
      <label for="municipalitySelector">#springMessageText('Address.municipality')</label>
      <input type="hidden" class="form-control" name="municipality" id="municipalitySelector" ui-select2="editCtrl.optionsSelectMunicipality" ng-model="center.address.municipality" required/>
       <cd-validation field="center.address.municipality" name="municipality" required="true" form="procedureForm" ctrl="editCtrl"></cd-validation>
     </div>
   </div>
市政府 #springMessageText('地址.市政')
正如我所说的,一切都很顺利,但这一例外情况令人担忧。当它们第一次出现时(使用选择器后),即使页面滚动事件也会触发它们,因此控制台中会打印大量异常。

是否可能是您试图在页面上生成它们之前访问它们?这是常见的情况。可能调用的代码应该包装在“onload”回调中。

您使用的是什么版本的Select2?我们使用的是带有AngularJS v1.2.10的Select2。否,页面已完全加载。它发生在使用选择器后滚动时。这很奇怪。有没有办法看到它在什么地方工作?也许我们可以一起调试调用堆栈。