IE中的Javascript错误(getElementsByTagName(…)。项(…)';为null或不是对象)

IE中的Javascript错误(getElementsByTagName(…)。项(…)';为null或不是对象),javascript,internet-explorer,getelementsbytagname,Javascript,Internet Explorer,Getelementsbytagname,希望使用Accuweather花粉计数谷歌应用程序,但它在IE中抛出了一个错误 以下是指向direct脚本的链接: 以下是有问题的环绕声脚本: function setContent(url) { _IG_FetchXmlContent(url, function (response) { if (!response) { msg.createDismissibleMessage("Error loadin

希望使用Accuweather花粉计数谷歌应用程序,但它在IE中抛出了一个错误

以下是指向direct脚本的链接:

以下是有问题的环绕声脚本:

        function setContent(url) {
        _IG_FetchXmlContent(url, function (response) {
            if (!response) {
                msg.createDismissibleMessage("Error loading location data. Please try again later.");
                echoDefault();
            } else if (response.firstChild.nodeName != 'error' &&
                parseInt(response.getElementsByTagName('citylist').item(0).getAttribute('us'))
                + parseInt(response.getElementsByTagName('citylist').item(0).getAttribute('intl'))
                + parseInt(response.getElementsByTagName('citylist').item(0).getAttribute('extra_cities'))) {
                mylocation = response.getElementsByTagName('location').item(0).getAttribute('location');
                url = 'http://whapw.accu-weather.com/widget/whapw/weather-data.asp?location=' + mylocation;

                _IG_FetchXmlContent(url, function (response) {
                    if (!response) {
                        msg.createDismissibleMessage("Error loading pollen data. Please try again later.");
                        echoDefault();
                    } else {
                        var tree = response.getElementsByTagName('tree').item(0).firstChild.nodeValue;
                        var weed = response.getElementsByTagName('weed').item(0).firstChild.nodeValue;
                        var grass = response.getElementsByTagName('grass').item(0).firstChild.nodeValue;
                        var mold = response.getElementsByTagName('mold').item(0).firstChild.nodeValue;
                        var airquality = response.getElementsByTagName('airquality').item(0).firstChild.nodeValue;
                        var airqualitytype = response.getElementsByTagName('airqualitytype').item(0).firstChild.nodeValue;
                        var airqualitystyle = '';
此行报告错误:

    } else if (response.firstChild.nodeName != 'error' &&
在FF/Chrome中工作良好,但在IE中我得到:

网页错误详细信息

用户代理:Mozilla/4.0(兼容;MSIE 8.0;Windows NT 6.1;Trident/4.0;SLCC2;.NET CLR 2.0.50727;.NET CLR 3.5.30729;.NET CLR 3.0.30729;Media Center PC 6.0;InfoPath.2;3M/MSIE 8.0) 时间戳:2011年8月5日星期五08:01:57 UTC

知道是什么导致了这个错误吗


提前感谢。

IE的某些版本有些奇怪,其中项(0)返回节点列表的长度,而不是第一项。相反,只需使用索引访问项目:

...getElementsByTagName('...')[0];

请添加代码的相关部分。脚本位于我发布的顶部链接(我对JS有点陌生,所以不知道代码的“相关”部分到底是什么)。没有人应该跟随链接来帮助你(如果将来无法访问该链接怎么办?这个问题变得毫无意义)。相关部分是抛出错误的行和周围的代码。这行代码所依赖的任何东西。好吧-我发布链接的原因是因为实际文件很大。我将在我的原始帖子中添加错误代码周围的行。谢谢,我已将项目(0)替换为[0],但是我现在似乎收到了“加载位置数据时出错,请重试”。你可以在这里查看:不过现在在IE中可以工作了。对不起,满是缩小的脚本。如果您希望我调试,您可能不喜欢我的速率。:-)恐怕这不是我的脚本,罗伯,这是我从Accuweather下载的谷歌小工具!我对Javascript一无所知,因此无法发表评论,但我相信你的话。只是想让它在IE中发挥作用。
...getElementsByTagName('...')[0];