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

vik*_*for 58 javascript internet-explorer

我的应用程序中有一个选项,用户可以在其中停用其配置文件.只有管​​理员可以再次激活它们.

我有一个ActivateProfile有两种方法的课

  • userExist(userName) 检查具有该userName的用户是否存在并且他/她的配置文件是否已停用
  • activateAccountByUser(userName)再次激活用户的个人资料

我在输入类型按钮的click事件上调用JavaScript函数.此代码适用于Chrome和Mozilla,但在Internet Explorer上我收到此错误:

SCRIPT438:Object不支持属性或方法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");
         }
      }});
   }
}
Run Code Online (Sandbox Code Playgroud)

以下是Activate配置文件类的代码

 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;
}
Run Code Online (Sandbox Code Playgroud)

vik*_*for 89

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

  • 有关如何在大型代码库中找到命名冲突的任何提示? (11认同)
  • 找到碰撞的解决方案:http://stackoverflow.com/questions/18434396/how-to-find-same-words-in-two-text-files-and-print-that-lines-ina-bash,http: //unix.stackexchange.com/questions/110645/select-lines-from-text-file-which-have-ids-listed-in-another-file或http://stackoverflow.com/questions/658351/how-找到的常见弦 - 中 - 双甚大文件 (3认同)
  • 我从来不知道造成这个问题的原因.很高兴终于知道了.应该让我未来的生活更轻松. (2认同)

rob*_*pim 8

这是使用JavaScript命名空间的Web应用程序中的常见问题.在这种情况下,99.9%的问题是IE无法将当前命名空间中的方法绑定到"this"关键字.

例如,如果我使用方法"isAwesome"的JS命名空间"StackOverflow".通常,如果您位于"StackOverflow"命名空间内,则可以使用以下语法调用"isAwesome"方法:

this.isAwesome();
Run Code Online (Sandbox Code Playgroud)

Chrome,Firefox和Opera很乐意接受这种语法.IE另一方面也不会.因此,使用JS命名空间时最安全的选择是始终使用实际命名空间作为前缀.一个la:

StackOverflow.isAwesome();
Run Code Online (Sandbox Code Playgroud)


Sum*_*P4U 5

我为corrosponding javascript中的所有变量添加了var.这解决了IE中的问题.

以前的代码

billableStatus = 1 ;
var classStr = $(this).attr("id").split("_");  
date = currentWeekDates[classStr[2]]; // Required    

activityNameId = "initialRows_" + classStr[1] + "_projectActivityName";
activityId = $("#"+activityNameId).val();        

var projectNameId = "initialRows_" + classStr[1] + "_projectName" ;
projectName = $("#"+projectNameId).val();        

var timeshitEntryId = "initialRows_"+classStr[1]+"_"+classStr[2];     
timeshitEntry = $("#"+timeshitEntryId).val();   
Run Code Online (Sandbox Code Playgroud)

新规范

var billableStatus = 1 ;
var classStr = $(this).attr("id").split("_");  
var date = currentWeekDates[classStr[2]]; // Required    

var activityNameId = "initialRows_" + classStr[1] + "_projectActivityName";
var activityId = $("#"+activityNameId).val();        

var projectNameId = "initialRows_" + classStr[1] + "_projectName" ;
var projectName = $("#"+projectNameId).val();        

var timeshitEntryId = "initialRows_"+classStr[1]+"_"+classStr[2];     
var timeshitEntry = $("#"+timeshitEntryId).val();   
Run Code Online (Sandbox Code Playgroud)