IE11中的JavaScript Datepicker问题 - crossobj.visibility =“hidden”;

时间:2014-06-26 15:26:39

标签: javascript datepicker internet-explorer-11

我们的应用程序是基于经销商的应用程序。这基本上是针对IE8浏览器实现的,现在由于经销商正在升级到IE11,我们在应用程序中面临很多问题(主要是UI)。其中一个问题是日期选择器。

当用户在IE11浏览器(兼容模式)中单击日期选择器时,日期选择器弹出窗口显示,而当用户在IE11浏览器(非兼容模式)中单击日期选择器时,则不执行任何操作。当我尝试在IE浏览器中使用开发人员工具调试这个时,我在控制台“SCRIPT5007:无法设置未定义或空引用的属性'可见性'中发现此错误”指向代码段“crossobj.visibility =”hidden“ ;”在函数hideCalendar()中。我试图在谷歌搜索任何类似的问题,但我没有找到任何所以我发布在这里。请查看错误并帮我解决此问题。

请在下面找到日期选择器的完整代码:

<script>
var pathURL = '<%=request.getContextPath()%>';

    var fixedX = -1;                // x position (-1 if to appear below control)
    var fixedY = -1;                // y position (-1 if to appear below control)
    var startAt = 1;                    // 0 - sunday ; 1 - monday
    var showWeekNumber = 0;         // 0 - don't show; 1 - show
    var showToday = 0;              // 0 - don't show; 1 - show
    var imgDir = "/DIMSWEB/images/";    // directory for images ... e.g. var imgDir="/img/"

    var titlebar="#969798";
    var highlight="#FFCC99";

    var gotoString = "Go To Current Month";
    var todayString = "Today is";
    var weekString = "Wk";
    var scrollLeftMessage = "Click to scroll to previous month. Hold mouse button to scroll automatically.";
    var scrollRightMessage = "Click to scroll to next month. Hold mouse button to scroll automatically.";
    var selectMonthMessage = "Click to select a month.";
    var selectYearMessage = "Click to select a year.";
    var selectDateMessage = "Select [date] as date."; // do not replace [date], it will be replaced by date.

    var crossobj, crossMonthObj, crossYearObj, monthSelected, yearSelected, dateSelected, omonthSelected, oyearSelected, odateSelected, monthConstructed, yearConstructed, intervalID1, intervalID2, timeoutID1, timeoutID2, ctlToPlaceValue, ctlNow, dateFormat, nStartingYear;

    var bPageLoaded=false;
    var ie=document.all;
    var dom=document.getElementById;

    var ns4=document.layers;
    var today = new Date();
    var dateNow  = today.getDate();
    var monthNow = today.getMonth();
    var yearNow  = today.getFullYear();
    var imgsrc = new Array("drop1.gif","drop2.gif","left1.gif","left2.gif","right1.gif","right2.gif");
    var img = new Array();
    var bShow = false;
    var calVal;
 /* hides <select> and <applet> objects (for IE only) */
 function hideElement( elmID, overDiv )
 {
   if( ie )
   {
     for( i = 0; i < document.all.tags( elmID ).length; i++ )
     {
       obj = document.all.tags( elmID )[i];
       if( !obj || !obj.offsetParent )
       {
         continue;
       }

       // Find the element's offsetTop and offsetLeft relative to the BODY tag.
       objLeft   = obj.offsetLeft;
       objTop    = obj.offsetTop;
       objParent = obj.offsetParent;

       while( objParent.tagName.toUpperCase() != "BODY" )
       {
         objLeft  += objParent.offsetLeft;
         objTop   += objParent.offsetTop;
         objParent = objParent.offsetParent;
       }

       objHeight = obj.offsetHeight;
       objWidth = obj.offsetWidth;

       if(( overDiv.offsetLeft + overDiv.offsetWidth ) <= objLeft );
       else if(( overDiv.offsetTop + overDiv.offsetHeight ) <= objTop );
       else if( overDiv.offsetTop >= ( objTop + objHeight ));
       else if( overDiv.offsetLeft >= ( objLeft + objWidth ));
       else
       {
         obj.style.visibility = "hidden";
       }
     }
   }
 }

 /*
 * unhides <select> and <applet> objects (for IE only)
 */
 function showElement( elmID )
 {
   if( ie )
   {
     for( i = 0; i < document.all.tags( elmID ).length; i++ )
     {
       obj = document.all.tags( elmID )[i];

       if( !obj || !obj.offsetParent )
       {
         continue;
       }

       obj.style.visibility = "";
     }
   }
 }


    if (dom)
    {
        for (i=0;i<imgsrc.length;i++)
        {
            img[i] = new Image
            img[i].src = imgDir + imgsrc[i]

                                         ///alert(img[i].src);
        }
        //Modified By Subhadip:On 07thAugust,2006
        document.write ("<div onclick='bShow=true' id='calendar' style='z-index:+999;position:absolute;visibility:hidden;width:100px'><table bgcolor='#969798' style='font-family:arial;font-size:10px;border-width:1;border-style:solid;border-color:#a0a0a0;font-family:arial; font-size:10px}' bgcolor='#ffffff'><tr bgcolor='" + titlebar + "'><td><table><tr><td style='padding:2px;font-family:arial; font-size:11px;'><font color='#ffffff'><B><span id='caption'></span></B></font></td><td align=right><a href='javascript:hideCalendar()'><img src='"+imgDir+"close.gif' width='15' height='13' border='0' alt='Close the Calendar'></a></td></tr></table></td></tr><tr><td style='padding:5px' bgcolor=#ffffff><span id='content1'></span></td></tr>")

        //Modified By Subhadip:On 07thAugust,2006   
        document.write ("</table></div><div id='selectMonth' style='z-index:+999;position:absolute;visibility:hidden;width:65px'></div><div id='selectYear' style='z-index:+999;position:absolute;visibility:hidden;width:45px'></div>");
    }

    //var   monthName = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
    var jan_key="<DimsBean:message key='january' langCode='${language}'></DimsBean:message>";
    var feb_key="<DimsBean:message key='february' langCode='${language}'></DimsBean:message>";
    var mar_key="<DimsBean:message key='march' langCode='${language}'></DimsBean:message>";
    var april_key="<DimsBean:message key='april' langCode='${language}'></DimsBean:message>";
    var may_key="<DimsBean:message key='may' langCode='${language}'></DimsBean:message>";
    var june_key="<DimsBean:message key='june' langCode='${language}'></DimsBean:message>";
    var july_key="<DimsBean:message key='july' langCode='${language}'></DimsBean:message>";
    var aug_key="<DimsBean:message key='august' langCode='${language}'></DimsBean:message>";
    var sep_key="<DimsBean:message key='september' langCode='${language}'></DimsBean:message>";
    var oct_key="<DimsBean:message key='october' langCode='${language}'></DimsBean:message>";
    var nov_key="<DimsBean:message key='november' langCode='${language}'></DimsBean:message>";
    var dec_key="<DimsBean:message key='december' langCode='${language}'></DimsBean:message>";


    var sun_key="<DimsBean:message key='sunday' langCode='${language}'></DimsBean:message>";
    var mon_key="<DimsBean:message key='monday' langCode='${language}'></DimsBean:message>";
    var tue_key="<DimsBean:message key='tuesday' langCode='${language}'></DimsBean:message>";
    var wed_key="<DimsBean:message key='wednesday' langCode='${language}'></DimsBean:message>";
    var thur_key="<DimsBean:message key='thursday' langCode='${language}'></DimsBean:message>";
    var fri_key="<DimsBean:message key='friday' langCode='${language}'></DimsBean:message>";
    var sat_key="<DimsBean:message key='saturday' langCode='${language}'></DimsBean:message>";


    var monthName = new Array(jan_key,feb_key,mar_key,april_key,may_key,june_key,july_key,aug_key,sep_key,oct_key,nov_key,dec_key);
    if (startAt==0)
    {
        dayName = new Array (sun_key,mon_key,tue_key,wed_key,thur_key,fri_key,sat_key)
    }
    else
    {
        dayName = new Array (mon_key,tue_key,wed_key,thur_key,fri_key,sat_key,sun_key)
    }
    var styleAnchor="text-decoration:none;color:black;"
    var styleLightBorder="border-style:solid;border-width:1px;border-color:#a0a0a0;"

    function swapImage(srcImg, destImg){
        if (ie) { document.getElementById(srcImg).setAttribute("src",imgDir + destImg) }
    }

    function init() {
        if (!ns4)
        {
            if (!ie) { yearNow += 1900; }

            crossobj=(dom)?document.getElementById("calendar").style : ie? document.all.calendar : document.calendar;
            hideCalendar();

            crossMonthObj=(dom)?document.getElementById("selectMonth").style : ie? document.all.selectMonth : document.selectMonth;

            crossYearObj=(dom)?document.getElementById("selectYear").style : ie? document.all.selectYear : document.selectYear;

            monthConstructed=false;
            yearConstructed=false;

            sHTML1="<span id='spanLeft' style='border-style:solid;border-width:1;border-color:#dddddd;cursor:pointer' onmouseover='swapImage(\"changeLeft\",\"left2.gif\");this.style.borderColor=\"white\";window.status=\""+scrollLeftMessage+"\"' onclick='javascript:decMonth()' onmouseout='clearInterval(intervalID1);swapImage(\"changeLeft\",\"left1.gif\");this.style.borderColor=\"#dddddd\";window.status=\"\"' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartDecMonth()\",500)'    onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<IMG id='changeLeft' SRC='"+imgDir+"left1.gif' width=10 height=11 BORDER=0>&nbsp</span>&nbsp;";
            sHTML1+="<span id='spanRight' style='border-style:solid;border-width:1;border-color:#dddddd;cursor:pointer' onmouseover='swapImage(\"changeRight\",\"right2.gif\");this.style.borderColor=\"white\";window.status=\""+scrollRightMessage+"\"' onmouseout='clearInterval(intervalID1);swapImage(\"changeRight\",\"right1.gif\");this.style.borderColor=\"#dddddd\";window.status=\"\"' onclick='incMonth()' onmousedown='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"StartIncMonth()\",500)'    onmouseup='clearTimeout(timeoutID1);clearInterval(intervalID1)'>&nbsp<IMG id='changeRight' SRC='"+imgDir+"right1.gif'   width=10 height=11 BORDER=0>&nbsp</span>&nbsp";
            sHTML1+="<span id='spanMonth' style='border-style:solid;border-width:1;border-color:#dddddd;cursor:pointer' onmouseover='swapImage(\"changeMonth\",\"drop2.gif\");this.style.borderColor=\"white\";window.status=\""+selectMonthMessage+"\"' onmouseout='swapImage(\"changeMonth\",\"drop1.gif\");this.style.borderColor=\"#dddddd\";window.status=\"\"' onclick='popUpMonth()'></span>&nbsp;";
            sHTML1+="<span id='spanYear' style='border-style:solid;border-width:1;border-color:#dddddd;cursor:pointer' onmouseover='swapImage(\"changeYear\",\"drop2.gif\");this.style.borderColor=\"white\";window.status=\""+selectYearMessage+"\"'   onmouseout='swapImage(\"changeYear\",\"drop1.gif\");this.style.borderColor=\"#dddddd\";window.status=\"\"'  onclick='popUpYear()'></span>&nbsp;";

            document.getElementById("caption").innerHTML  = sHTML1;

            bPageLoaded=true;
        }
    }

    function hideCalendar() {
        crossobj.visibility="hidden";
        if (crossMonthObj != null){crossMonthObj.visibility="hidden";}
        if (crossYearObj != null){crossYearObj.visibility="hidden";}

        showElement( 'SELECT' );
        showElement( 'APPLET' );
    }

    function padZero(num) {
        return (num < 10)? '0' + num : num ;
    }

    function constructDate(d,m,y)
    {
        sTmp = dateFormat
        sTmp = sTmp.replace ("dd","<e>")
        sTmp = sTmp.replace ("d","<d>")
        sTmp = sTmp.replace ("<e>",padZero(d))
        sTmp = sTmp.replace ("<d>",d)
        sTmp = sTmp.replace ("mmm","<o>")
        sTmp = sTmp.replace ("mm","<n>")
        sTmp = sTmp.replace ("m","<m>")
        sTmp = sTmp.replace ("<m>",m+1)
        sTmp = sTmp.replace ("<n>",padZero(m+1))
        sTmp = sTmp.replace ("<o>",monthName[m])
        sTmp = sTmp.replace ("yyyy",y)
        sTmp = sTmp.replace ("yy",y.toString().substr(2,2))
        return sTmp
    }

    function closeCalendar() {
        var sTmp

        hideCalendar();
        //ctlToPlaceValue.value =   constructDate(dateSelected,monthSelected,yearSelected.toString().substr(2,2))
        ctlToPlaceValue.value = constructDate(dateSelected,monthSelected,yearSelected.toString())
        calVal=ctlToPlaceValue.value;
    }

    /*** Month Pulldown ***/

    function StartDecMonth()
    {
        intervalID1=setInterval("decMonth()",80)
    }

    function StartIncMonth()
    {
        intervalID1=setInterval("incMonth()",80)
    }

    function incMonth () {
        monthSelected++
        if (monthSelected>11) {
            monthSelected=0
            yearSelected++
        }
        constructCalendar()
    }

    function decMonth () {
        monthSelected--
        if (monthSelected<0) {
            monthSelected=11
            yearSelected--
        }
        constructCalendar()
    }

    function constructMonth() {
        popDownYear()
        if (!monthConstructed) {
            sHTML = ""
            for (i=0; i<12; i++) {
                sName = monthName[i];
                if (i==monthSelected){
                    sName = "<B>" + sName + "</B>"
                }
                sHTML += "<tr><td id='m" + i + "' onmouseover='this.style.backgroundColor=\"#dddddd\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='monthConstructed=false;monthSelected=" + i + ";constructCalendar();popDownMonth();event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
            }

            document.getElementById("selectMonth").innerHTML = "<table width=70 style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;' bgcolor='white' cellspacing=0 onmouseover='clearTimeout(timeoutID1)'   onmouseout='clearTimeout(timeoutID1);timeoutID1=setTimeout(\"popDownMonth()\",100);event.cancelBubble=true'>" + sHTML + "</table>"

            monthConstructed=true
        }
    }

    function popUpMonth() {
        constructMonth()
        crossMonthObj.visibility = (dom||ie)? "visible" : "show"
        crossMonthObj.left = parseInt(crossobj.left) + 50
        crossMonthObj.top = parseInt(crossobj.top) + 26

        hideElement( 'SELECT', document.getElementById("selectMonth") );
        hideElement( 'APPLET', document.getElementById("selectMonth") );            
    }

    function popDownMonth() {
        crossMonthObj.visibility= "hidden"
    }

    /*** Year Pulldown ***/

    function incYear() {
        for (i=0; i<7; i++){
            newYear = (i+nStartingYear)+1
            if (newYear==yearSelected)
            { txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;" }
            else
            { txtYear = "&nbsp;" + newYear + "&nbsp;" }
            document.getElementById("y"+i).innerHTML = txtYear
        }
        nStartingYear ++;
        bShow=true
    }

    function decYear() {
        for (i=0; i<7; i++){
            newYear = (i+nStartingYear)-1
            if (newYear==yearSelected)
            { txtYear = "&nbsp;<B>" + newYear + "</B>&nbsp;" }
            else
            { txtYear = "&nbsp;" + newYear + "&nbsp;" }
            document.getElementById("y"+i).innerHTML = txtYear
        }
        nStartingYear --;
        bShow=true
    }

    function selectYear(nYear) {
        yearSelected=parseInt(nYear+nStartingYear);
        yearConstructed=false;
        constructCalendar();
        popDownYear();
    }

    function constructYear() {
        popDownMonth()
        sHTML = ""
        if (!yearConstructed) {

            sHTML = "<tr><td align='center' onmouseover='this.style.backgroundColor=\"white\"' onmouseout='clearInterval(intervalID1);this.style.backgroundColor=\"\"' style='cursor:pointer'   onmousedown='clearInterval(intervalID1);intervalID1=setInterval(\"decYear()\",30)' onmouseup='clearInterval(intervalID1)'>-</td></tr>"

            j = 0
            nStartingYear = yearSelected-3
            for (i=(yearSelected-3); i<=(yearSelected+3); i++) {
                sName = i;
                if (i==yearSelected){
                    sName = "<B>" + sName + "</B>"
                }

                sHTML += "<tr><td id='y" + j + "' onmouseover='this.style.backgroundColor=\"#dddddd\"' onmouseout='this.style.backgroundColor=\"\"' style='cursor:pointer' onclick='selectYear("+j+");event.cancelBubble=true'>&nbsp;" + sName + "&nbsp;</td></tr>"
                j ++;
            }

            sHTML += "<tr><td align='center' onmouseover='this.style.backgroundColor=\"white\"' onmouseout='clearInterval(intervalID2);this.style.backgroundColor=\"\"' style='cursor:pointer' onmousedown='clearInterval(intervalID2);intervalID2=setInterval(\"incYear()\",30)'   onmouseup='clearInterval(intervalID2)'>+</td></tr>"

            document.getElementById("selectYear").innerHTML = "<table width=44 style='font-family:arial; font-size:11px; border-width:1; border-style:solid; border-color:#a0a0a0;' bgcolor='white' onmouseover='clearTimeout(timeoutID2)' onmouseout='clearTimeout(timeoutID2);timeoutID2=setTimeout(\"popDownYear()\",100)' cellspacing=0>"   + sHTML + "</table>"

            yearConstructed = true
        }
    }

    function popDownYear() {
        clearInterval(intervalID1)
        clearTimeout(timeoutID1)
        clearInterval(intervalID2)
        clearTimeout(timeoutID2)
        crossYearObj.visibility= "hidden"
    }

    function popUpYear() {
        var leftOffset

        constructYear()
        crossYearObj.visibility = (dom||ie)? "visible" : "show"
        leftOffset = parseInt(crossobj.left) + document.getElementById("spanYear").offsetLeft
        if (ie)
        {
            leftOffset += 6
        }
        crossYearObj.left = leftOffset
        crossYearObj.top = parseInt(crossobj.top) + 26
    }

    /*** calendar ***/

    function constructCalendar () {
        var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31)

        var dateMessage
        var startDate = new Date (yearSelected,monthSelected,1)
        var endDate
        var colColour="bgcolor=white";
        var bSwitch;
        var nMax;

        if (monthSelected==1)
        {
            endDate = new Date (yearSelected,monthSelected+1,1);
            endDate = new Date (endDate - (24*60*60*1000));
            numDaysInMonth = endDate.getDate()
        }
        else
        {
            numDaysInMonth = aNumDays[monthSelected];
        }

        datePointer = 0
        dayPointer = startDate.getDay() - startAt

        if (dayPointer<0)
        {
            dayPointer = 6
        }

        sHTML = "<table  border=1 cellspacing=0 style='font-family:arial;font-size:10px;'><tr>"

//Set up row of Day Headings

        for (i=0; i<7; i++) {
            sHTML += "<td width='27' align='right' bgcolor='#dddddd'><B>"+ dayName[i].substr(0,3)+"</B></td>"
        }
        sHTML +="</tr><tr>"

//Fill in empty columns before start day
        for ( var i=1; i<=dayPointer;i++ )
        {
           if ((i%2))          
               sHTML += "<td bgcolor='white'>&nbsp;</td>"
           else    
               sHTML += "<td bgcolor='#dddddd'>&nbsp;</td>"
        }   
        if (dayPointer%2)
           bSwitch=false;
        else
           bSwitch=true;   

        for ( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )
        {       
            dayPointer++;           

            if (bSwitch)
                 colColour=" bgcolor='white'";
            else
                 colColour=" bgcolor='#dddddd'";      

            sHTML += "<td align=right" + colColour +  ">"
            sStyle=styleAnchor
            if ((datePointer==odateSelected) && (monthSelected==omonthSelected) && (yearSelected==oyearSelected))
            { sStyle+=styleLightBorder }

            sHint = ""

            var regexp= /\"/g
            sHint=sHint.replace(regexp,"&quot;")

            dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected))+"\"' onmouseout='window.status=\"\"' "

            if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow))
            { sHTML += "<b><a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer+";closeCalendar();'><font color=#ff0000>&nbsp;" + datePointer + "</font>&nbsp;</a></b>"}
            else if (dayPointer % 7 == (startAt * -1)+1) //Sunday
            { sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'>&nbsp;<font color=#909090>" + datePointer + "</font>&nbsp;</a>" }
            else
            { sHTML += "<a "+dateMessage+" title=\"" + sHint + "\" style='"+sStyle+"' href='javascript:dateSelected="+datePointer + ";closeCalendar();'>&nbsp;" + datePointer + "&nbsp;</a>" }

            bSwitch=!bSwitch

            sHTML += ""
            if ((dayPointer+startAt) % 7 == startAt) { 
                bSwitch=true;
                sHTML += "</tr><tr>" 
            }
        }
//Add on as many empty cells as required to fill row        

        if (dayPointer > 35)
            nMax = 42;
        else
            nMax = 35;

        for ( var i=1; i<=(nMax-dayPointer);i++ )
        {
           if (bSwitch)        
               sHTML += "<td bgcolor='white'>&nbsp;</td>"
           else    
               sHTML += "<td bgcolor='#dddddd'>&nbsp;</td>"
            bSwitch=!bSwitch
        }   

        document.getElementById("content1").innerHTML   = sHTML
        document.getElementById("spanMonth").innerHTML = "&nbsp;" + monthName[monthSelected] + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<IMG id='changeMonth' SRC='/DIMSWEB/images/drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
        document.getElementById("spanYear").innerHTML = "&nbsp;" + yearSelected + "&nbsp;<IMG id='changeYear' SRC='/DIMSWEB/images/drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
    }

    function popUpCalendar(ctl, ctl2, format) {
        var leftpos=0
        var toppos=0

        if (bPageLoaded)
        {

            if ( crossobj.visibility == "hidden" ) {
                ctlToPlaceValue = ctl2
                dateFormat=format;

                formatChar = " "
                aFormat = dateFormat.split(formatChar)
                if (aFormat.length<3)
                {
                    formatChar = "/"
                    aFormat = dateFormat.split(formatChar)
                    if (aFormat.length<3)
                    {
                        formatChar = "."
                        aFormat = dateFormat.split(formatChar)
                        if (aFormat.length<3)
                        {
                            formatChar = "-"
                            aFormat = dateFormat.split(formatChar)
                            if (aFormat.length<3)
                            {
                                // invalid date format
                                formatChar=""
                            }
                        }
                    }
                }


                tokensChanged = 0
                if ( formatChar != "" )
                {
                    // use user's date
                    aData = ctl2.value.split(formatChar)

                    for (i=0;i<3;i++)
                    {
                        if ((aFormat[i]=="d") || (aFormat[i]=="dd"))
                        {
                            dateSelected = parseInt(aData[i], 10)
                            tokensChanged ++
                        }
                        else if ((aFormat[i]=="m") || (aFormat[i]=="mm"))
                        {
                            monthSelected = parseInt(aData[i], 10) - 1
                            tokensChanged ++
                        }
                        else if (aFormat[i]=="yyyy")
                        {
                            yearSelected = parseInt(aData[i], 10)
                            tokensChanged ++
                        }
                        else if (aFormat[i]=="yy")
                        {
                            if (aData[i]>50)
                            {
                               tempYear = parseInt(1900 + parseInt(aData[i]))
                            }
                            else
                            {
                               tempYear = parseInt(2000 + parseInt(aData[i]))
                            }
                            yearSelected = parseInt(tempYear, 10)
                            tokensChanged ++
                        }
                        else if (aFormat[i]=="mmm")
                        {
                            for (j=0; j<12; j++)
                            {
                                if (aData[i]==monthName[j])
                                {
                                    monthSelected=j
                                    tokensChanged ++
                                }
                            }
                        }                       
                    }
                }

                if ((tokensChanged!=3)||isNaN(dateSelected)||isNaN(monthSelected)||isNaN(yearSelected))
                {
                    dateSelected = dateNow
                    monthSelected = monthNow
                    yearSelected = yearNow
                }

                odateSelected=dateSelected
                omonthSelected=monthSelected
                oyearSelected=yearSelected

                aTag = ctl
                do {
                    aTag = aTag.offsetParent;

                    if(aTag.offsetLeft>=600){
                        leftpos += (aTag.offsetLeft-200);
                    }
                    else{
                        leftpos += aTag.offsetLeft;
                    }

                    toppos += aTag.offsetTop;
                } while(aTag.tagName!="BODY");

                crossobj.left = fixedX==-1 ? ctl.offsetLeft + leftpos : fixedX
                crossobj.top = fixedY==-1 ? ctl.offsetTop + toppos + ctl.offsetHeight + 2 : fixedY
                constructCalendar (1, monthSelected, yearSelected);
                crossobj.visibility=(dom||ie)? "visible" : "show"

                hideElement( 'SELECT', document.getElementById("calendar") );
                hideElement( 'APPLET', document.getElementById("calendar") );           

                bShow = true;
            }
            else
            {
                hideCalendar()
                if (ctlNow!=ctl) {popUpCalendar(ctl, ctl2, format);}
            }
            ctlNow = ctl;
        }
        return calVal;
    }

    document.onkeypress = function hidecal1 () { 
        if (event.keyCode==27) 
        {
            hideCalendar();
        }
    }
    document.onclick = function hidecal2 () {       
        if (!bShow)
        {
            hideCalendar();
        }
        bShow = false
    }

    if(ie)  
    {
        init()
    }
    else
    {
        window.onload=init
    }

    function Navigate(obj,strURL,plsEnterUDate,noPastUDate,notValidYr){     
    var index = obj.getElementById("selLocationCode").selectedIndex;
    var selLocation = obj.getElementById("selLocationCode").options(index).value;
    var selCodeDesc = selLocation.split(",");
    obj.getElementById("hdLocationCode").value=selCodeDesc[0];

    obj.getElementById("hdLocationDesc").value=selCodeDesc[1];



    //frmLocUnavailAdd_onSubmit(obj);
        if(frmLocUnavailAdd_onSubmit(obj,plsEnterUDate,noPastUDate,notValidYr))
        {
            obj.frmLocUnavailAdd.action = strURL;
            obj.frmLocUnavailAdd.submit();        
        }
    }

    function Navigate1(obj,strURL,plsEnterUDate,noPastUDate,notValidYr){

    //frmLocUnavailAdd_onSubmit(obj);
    if(frmLocUnavailAdd_onSubmit(obj,plsEnterUDate,noPastUDate,notValidYr))
        {
          obj.frmLocUnavailAdd.action = strURL;
          obj.frmLocUnavailAdd.submit();          
        }
    }

</script>

请注意, 1.我不能要求经销商打开兼容模式并开始使用我需要代码修复的应用程序来解决问题。 2.我也尝试使用DocType标签来解决,但这没有帮助。 3.我最后删除了一些字符长度限制的函数。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

问题是您在那里设置了特定于IE的代码crossobj

crossobj=(dom)?document.getElementById("calendar").style : ie? document.all.calendar : document.calendar;

在上面的代码行中,它会检查一个名为ie的变量,以确定浏览器是否为IE,如果是,则会向其他浏览器运行不同的代码。

使用此代码的问题在于,IE11比旧版IE更符合标准,因此根本不需要这种代码。

(事实上,即使IE8在这种情况下也不应该需要它;它显然针对的是更旧的版本。而且我注意到你在那里也有ns4的浏览器检查,它立即告诉我您的原始脚本是非常古老的代码)

我的建议是考虑用更现代和最新的日历控件替换整个代码。有很多可用的,可以在所有当前浏览器中使用,并且应该很容易插入您的网站。

如果您绝对必须保留现有代码,那么快速而又脏的修复方法是找到它设置ie变量的位置,并更改浏览器检测以使其仅检测IE8及更早版本(或任何版本)使用它,以便IE11不被检测为IE,因此充当“正常”浏览器。这可能会解决手头的问题,但可能会产生其他意想不到的后果,所以我建议你最好去通过代码并删除所有浏览器检测的东西。我的猜测是,即使对于IE8,大部分都是完全没必要的。可能会有一些重写要做,但考虑到年龄,它可能不是一件坏事代码。

如果您确实发现自己需要某些特定于浏览器的代码,请考虑使用像Modernizr这样的工具来检测对给定功能的支持,而不是直接检测浏览器。

希望有所帮助。