简体   繁体   English

Javascript错误:ie6和ie7中需要对象

[英]Javascript error: Object Required in ie6 & ie7

I have a javascript function (epoch calendar) which displays a calendar when focus is set on certain text boxes. 我有一个javascript函数(纪元日历),当将焦点设置在某些文本框上时会显示一个日历。 this works fine in ie8, ff (all versions as far as I can test), opera etc but doesn't work in ie7 or previous. 这在ie8,ff(我可以测试的所有版本),opera等中都能正常工作,但在ie7或更早版本中不起作用。

If i have it set up in a blank html test page it will work so I'm fairly sure it's a conflict with my css (provided to me by a designer). 如果我将其设置在空白的html测试页中,它将可以正常运行,因此我可以确定这与css(由设计师提供)冲突。

I've traced the error to these lines of code - 我已将错误追溯到这些代码行-

Epoch.prototype.getTop = function (element) //PRIVATE: returns the absolute Top value of element, in pixels
{
    var oNode = element;
    var iTop = 0;

    while(oNode.tagName != 'BODY') {
        iTop += oNode.offsetTop;
        oNode = oNode.offsetParent;
    }

    return iTop;
};

Epoch.prototype.getLeft = function (element) //PRIVATE: returns the absolute Left value of element, in pixels
{
    var oNode = element;
    var iLeft = 0;

    while(oNode.tagName != 'BODY') {
        iLeft += oNode.offsetLeft;
        oNode = oNode.offsetParent;        
    }

    return iLeft;
};

More specifically, if i remove the actual while loops then the calendar will display OK, just that its positioning on the page is wrong? 更具体地说,如果我删除实际的while循环,则日历将显示OK,只是其在页面上的位置错误?

EDIT 编辑

Code below which sets 'element' 下面的代码设置了“元素”

<script type="text/javascript">

        window.onload = function() {
            var bas_cal, dp_cal, ms_cal;
            dp_cal = new Epoch('epoch_popup', 'popup', document.getElementById('<%=txtDateOfDiag.ClientID%>'));
            dp_cal = new Epoch('epoch_popup', 'popup', document.getElementById('<%=txtDOB.ClientID%>'));
        };

</script>

Note: I am using asp.net Master pages which is why there is a need for the .ClientID 注意:我正在使用asp.net母版页,这就是为什么需要.ClientID的原因

EDIT 编辑

A further update - I have recreated this without applying css (but including the .js file provided by the designer) the code still works fine which, there must be some sort of conflict between the CSS and my JavaScript? 进一步的更新-我在没有应用CSS的情况下重新创建了该代码(但包括设计者提供的.js文件),代码仍然可以正常工作,这在CSS和JavaScript之间是否存在某种冲突?

That would lead me to believe that the tagName does not match, possibly because you have it in upper case. 那会让我相信tagName不匹配,可能是因为您使用大写字母。 You might try while(!oNode.tagName.match(/body/i)) { 您可以尝试while(!oNode.tagName.match(/body/i)) {

what happens if you add a line of debug code like this: 如果添加以下调试代码,会发生什么情况:

var oNode = element;
var iLeft = 0;  
alert(oNode);

This might give different results in different browsers; 这可能在不同的浏览器中产生不同的结果。 I think it may be NULL for IE. 我认为对于IE可能为NULL。
You may want to have a look at the code that provides the value of the 'element' parameter to see if there's a browser-dependant issue there. 您可能需要看一下提供'element'参数值的代码,以查看是否存在与浏览器有关的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM