SCRIPT438:对象不支持属性或方法IE

问题描述

经过几天的搜索,我发现当html元素ID与javascript函数中的某些变量具有相同的id时,通常会发生此错误。更改其中一个的名称后,我的代码运行正常。

解决方法

我的应用程序中有一个选项,用户可以停用其个人资料。只有管​​理员可以再次激活它们。

我有一类ActivateProfile有两种方法

  • userExist(userName) 检查具有该userName的用户是否存在并且其个人资料已停用
  • 然后activateAccountByUser(userName)再次激活用户的个人资料

我在输入类型按钮的click事件上调用JavaScript函数。这段代码在Chrome和Mozilla上正常运行,但是在Internet
Explorer上却出现此错误:

SCRIPT438:对象不支持属性或方法userExist

function activateProf() {        
   var userName=document.getElementById("userName").value;

   if (userName == "") {
      alert("Полето е задолжително");
   } else {
      alert(userName + "1");
      ActivateProfile.userExist(userName,{ callback:function(exist) {
         if (userName) {
            ActivateProfile.activateAccountByUser(userName);
            alert("User is activated");
         } else {
            alert("User does not exist");
         }
      }});
   }
}

这是激活配置文件类的代码

 public void activateAccountByUser(String userName) {
    try {
        Connection c = DBComm.getInstance().getConnection();
        Statement s = c.createStatement();
        ResultSet set = s.executeQuery("select * from accounts where userName = '" + userName + "' and isauthorized='2'");

        if (set.next()) {
            Statement st = c.createStatement();
            st.executeUpdate("update accounts set isauthorized='1' where userName='" + userName                    + "' and isauthorized='2'");
        }
        s.close();
        c.close();
    } catch (Exception ex) {
        java.util.logging.Logger.getLogger(ActivateProfile.class.getName()).log(Level.SEVERE,null,ex);
    }
}

public boolean userExist(String userName) throws SQLException {
    //true exist
    //false does not exist
    boolean existEmbg = false;

    try {
        Connection c = DBComm.getInstance().getConnection();
        Statement s = c.createStatement();
        ResultSet set = s.executeQuery("select * from accounts where userName = '" + userName + "' and isauthorized='2'");

        if (set.next()) {
            existEmbg = true;
        } else {
            existEmbg = false;
        }
        s.close();
        c.close();
    } catch (Exception ex) {
       java.util.logging.Logger.getLogger(ActivateProfile.class.getName()).log(Level.SEVERE,ex);
    }
    return existEmbg;
}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...