对象不支持javascript中的ie8中的此属性或方法 [英] Object doesn't support this property or method in ie8 for javascript

查看:534
本文介绍了对象不支持javascript中的ie8中的此属性或方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个ASP应用程序,但我得到这个错误在IE 8:

I am working on an ASP application but I get this error in IE 8:


消息:对象不支持此属性或方法

Message: Object doesn't support this property or method

行:216

Char:8

代码:0

这是我的代码:

$(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
    });
 });


推荐答案

您的代码受到 隐藏全域的恐怖 ,所以我怀疑今天是通过非JavaScript机制创建的全局,不允许您为其分配 Date 对象。

Your code falls prey to The Horror of Implicit Globals and 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.

您需要使用关键字 var 声明您的本地变量。我怀疑会解决你有的问题。例如。 (注意前四行):

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):

$(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
    });
});






旁注:JavaScript中的压倒性约定是变量以小写字母开头(今天而不是今天)。使用大写字符( Today )启动某个东西通常只对构造函数(例如 Date )。


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中的ie8中的此属性或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆