对象在 ie8 for javascript 中不支持此属性或方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19397530/
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
Object doesn't support this property or method in ie8 for javascript
提问by Anup Karanjkar
I am working on an ASP application but I get this error in IE 8:
我正在开发一个 ASP 应用程序,但在 IE 8 中出现此错误:
Message: Object doesn't support this property or method
Line: 216
Char: 8
Code: 0
消息:对象不支持此属性或方法
线路:216
字符:8
代码:0
This is my code:
这是我的代码:
$(function() {
Today = new Date;
Annee = Today.getFullYear() - 18 ; //this is a Line 216
PlageMois = Today.getMonth();
Jour = Today.getDate() ;
//maxDate: new Date(new Date.getFullYear(), 1-1, 1),
$( "#datepicker_Majeur" ).datepicker({
monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug','Sep', 'Oct', 'Nov', 'Dec'],
dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'],
dateFormat: 'mm/dd/yy',
//maxDate: new Date(1993, 1-1, 1),
maxDate: new Date(Annee, PlageMois, Jour),
showOn: "button",
buttonImage: "/images/img-calendar.gif",
buttonImageOnly: true
});
});
回答by T.J. Crowder
Your code falls prey to The Horror of Implicit Globalsand so I suspect Today
is a global being created via a non-JavaScript mechanism that doesn't let you assign a Date
object to it.
您的代码成为隐式全局变量的牺牲品,因此我怀疑Today
是通过非 JavaScript 机制创建的全局变量,该机制不允许您为其分配Date
对象。
You need to declare your local variables with the keyword var
. I suspect that will resolve the problem you're having. E.g. (note the first four lines):
您需要使用关键字 声明局部变量var
。我怀疑这将解决您遇到的问题。例如(注意前四行):
$(function() {
var Today = new Date;
var Annee = Today.getFullYear() - 18 ; //this is a Line 216
var PlageMois = Today.getMonth();
var Jour = Today.getDate() ;
//maxDate: new Date(new Date.getFullYear(), 1-1, 1),
$( "#datepicker_Majeur" ).datepicker({
monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug','Sep', 'Oct', 'Nov', 'Dec'],
dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'],
dateFormat: 'mm/dd/yy',
//maxDate: new Date(1993, 1-1, 1),
maxDate: new Date(Annee, PlageMois, Jour),
showOn: "button",
buttonImage: "/images/img-calendar.gif",
buttonImageOnly: true
});
});
Side note: The overwhelming convention in JavaScript is for variables to start with a lower-case letter (today
rather than Today
). Starting something with an upper-case character (Today
) is usually only done for constructor functions(like Date
).
旁注:JavaScript 中压倒性的约定是变量以小写字母(today
而不是Today
)开头。以大写字符 ( Today
) 开头的内容通常仅用于构造函数(如Date
)。