Javascript SCRIPT438:对象不支持属性或方法 IE
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13975922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SCRIPT438: Object doesn't support property or method IE
提问by vikifor
I have an option in my application where users can deactivate their profiles. Only admin can activate them again.
我的应用程序中有一个选项,用户可以在其中停用他们的个人资料。只有管理员可以再次激活它们。
I have a class ActivateProfilewith two methods
我有一个ActivateProfile有两种方法的类
userExist(userName)that checks if user with that userName exists and his/her profile is deactivated- and
activateAccountByUser(userName)that activate the profile of the user again
userExist(userName)检查具有该用户名的用户是否存在并且他/她的个人资料是否已停用- 并
activateAccountByUser(userName)再次激活用户的个人资料
I call a JavaScript function on the click event of an input type button. This code works fine on Chrome and Mozilla, but on Internet Explorer I get this error:
我在输入类型按钮的单击事件上调用 JavaScript 函数。此代码在 Chrome 和 Mozilla 上运行良好,但在 Internet Explorer 上出现此错误:
SCRIPT438: Object doesn't support property or method userExist
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");
}
}});
}
}
Here is the code for Activate profile class
这是激活配置文件类的代码
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;
}
回答by vikifor
After some days searching the Internet I found that this error usually occurs when an html element id has the same id as some variable in the javascript function. After changing the name of one of them my code was working fine.
经过几天的互联网搜索,我发现当 html 元素 id 与 javascript 函数中的某个变量具有相同的 id 时,通常会发生此错误。更改其中之一的名称后,我的代码运行良好。
回答by pimbrouwers
This is a common problem in web applications which employ JavaScript namespacing. When this is the case, the problem 99.9% of the time is IE's inability to bind methods within the current namespace to the "this" keyword.
这是使用 JavaScript 命名空间的 Web 应用程序中的常见问题。在这种情况下,99.9% 的问题是 IE 无法将当前命名空间中的方法绑定到“this”关键字。
For example, if I have the JS namespace "StackOverflow" with the method "isAwesome". Normally, if you are within the "StackOverflow" namespace you can invoke the "isAwesome" method with the following syntax:
例如,如果我有 JS 命名空间“StackOverflow”和方法“isAwesome”。通常,如果您在“StackOverflow”命名空间内,您可以使用以下语法调用“isAwesome”方法:
this.isAwesome();
Chrome, Firefox and Opera will happily accept this syntax. IE on the other hand, will not. Thus, the safest bet when using JS namespacing is to always prefix with the actual namespace. A la:
Chrome、Firefox 和 Opera 很乐意接受这种语法。另一方面,IE 不会。因此,使用 JS 命名空间时最安全的选择是始终以实际命名空间为前缀。啦啦:
StackOverflow.isAwesome();
回答by Suman-PHP4U
I have added var for all the variables in the corrosponding javascript. That solved the problem in IE.
我已经为相应的 javascript 中的所有变量添加了 var。这解决了IE中的问题。
Previous Code
以前的代码
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();
New Code
新代码
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();
回答by Lynxy
My problem was having type="application/javascript"on the <script>tag for jQuery. IE8 does not like this! If your webpage is HTML5 you don't even need to declare the type, otherwise go with type="text/javascript"instead.
我的问题是type="application/javascript"在<script>jQuery 标签上。IE8 不喜欢这个!如果您的网页是 HTML5,您甚至不需要声明类型,否则请type="text/javascript"改用。
回答by osoitza
In my case I had code like this:
就我而言,我有这样的代码:
function.call(context, arg);
I got error message under IE
我在 IE 下收到错误消息
TypeError: Object doesn't support property or method 'error'
类型错误:对象不支持属性或方法“错误”
In the body of 'function' I had "console.error" and it turns that console object is undefined when your console is closed. I have fixed this by checking if console and console.error are defined
在“函数”的主体中,我有“console.error”,当您的控制台关闭时,它会导致控制台对象未定义。我通过检查是否定义了 console 和 console.error 来解决这个问题
回答by Alex
Implement "use strict"in all script tags to find inconsistencies and fix potential unscoped variables!
"use strict"在所有脚本标签中实施以查找不一致并修复潜在的无作用域变量!
回答by Justin E. Samuels
We were able to solve this problem by adding in the Object.Assign polyfill to the files being imported and throwing the error. We would make it the highest import, that way it would be available to the other code to be called in the stack.
我们能够通过将 Object.Assign polyfill 添加到正在导入的文件中并抛出错误来解决这个问题。我们将其设为最高的导入,这样它就可用于堆栈中要调用的其他代码。
import "mdn-polyfills/Object.assign";
import "mdn-polyfills/Object.assign";
回答by Jamil Haddadin
I forgot to use varon my item variable
我忘了var在我的项目变量上使用
Incorrect code:
不正确的代码:
var itemCreateInfo = new SP.ListItemCreationInformation();
item = list.addItem(itemCreateInfo);
item.set_item('Title', 'Haytham - Oil Eng');
Correct code:
正确代码:
var itemCreateInfo = new SP.ListItemCreationInformation();
var item = list.addItem(itemCreateInfo);
item.set_item('Title', 'Haytham - Oil Eng');
回答by Sameer
This issue may be occurred due to improper jquery version. like 1.4 etc. where done method is not supported
此问题可能是由于 jquery 版本不正确造成的。像 1.4 等,不支持 done 方法
回答by blong824
I had the following
我有以下
document.getElementById("search-button") != null
which worked fine in all browsers except ie8. ( I didnt check ie6 or ie7)
它在除 ie8 之外的所有浏览器中都运行良好。(我没有检查 ie6 或 ie7)
I changed it to
我把它改成
document.getElementById("searchBtn") != null
and updated the id attribute on the field in my html and it now works in ie8
并更新了我的 html 字段上的 id 属性,它现在可以在 ie8 中使用

