javascript - 脚本 438 : Object doesn't support property or method IE

标签 javascript internet-explorer

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

我有一个类 ActivateProfile 有两个方法

  • userExist(userName) 检查具有该用户名的用户是否存在以及他/她的个人资料是否已停用
  • activateAccountByUser(userName)再次激活用户的个人资料

我在输入类型按钮的点击事件上调用 JavaScript 函数。此代码在 Chrome 和 Mozilla 上运行良好,但在 Internet Explorer 上出现此错误:

SCRIPT438: Object doesn't support property or method 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, null, ex);
    }
    return existEmbg;
}

最佳答案

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

关于javascript - 脚本 438 : Object doesn't support property or method IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13975922/

相关文章:

c# - 在 ASP.Net 中使用 JavaScript

internet-explorer - Sammy.js 路由未从 IE10 中的 Knockout-bound 链接触发

javascript - 在 Safari 中失去内容可编辑的焦点

javascript - 我无法使用 Phaser 3 中的创建功能将任何内容加载到 Canvas 上

css - 与 Firefox/Chrome 相比,IE 中的蓝图站点完全不同

html - Internet Explorer 在 JQuery .hide() 上崩溃

c# - Internet Explorer 滞后于 IQueryable 数据源。 Firefox 和 Chrome A-OK。提供视频证明

asp.net - Internet Explorer 8 & 9 向样式显示为 :table-cell 的 div 添加偏移量或边距

javascript - session 登录后 Jquery 移动导航栏不活动(Rails)

javascript - 函数无法正确读取状态值