为什么这个类仅在某些执行时显示为“未定义”?

时间:2015-06-20 21:51:19

标签: javascript

我在一个文档中有一个输入元素类:

inputClass.js:

function inputField(name) {
    this.elem = document.getElementsByName(name);
    this.type = this.elem[0].type;
    this.name = name;
    this.label = this.labelCheck();

    inputField.getVal = function () {
      switch (this.type) {
        case "checkbox":
        case "radio":
          return ;
      }
    };
  }

当我在主脚本中创建一个实例时,它可以工作,但在某些执行中,我得到了这个:

ReferenceError: inputField is not defined
var user = new inputField('user');

它会工作,但如果我刷新一次或两次,我会得到Reference错误。然后我再次刷新,没关系。怎么解释这个?

0 个答案:

没有答案
相关问题