简体   繁体   English

IE7 Ajax加载图像问题-CSS属性显示不起作用

[英]IE7 Ajax load image issue - css property display not working

I am trying to display an image conditionally - but it is not working only in IE Browser. 我试图有条件地显示图像-但它仅在IE浏览器中不起作用。 In Firefox , it is working correctly. 在Firefox中,它可以正常工作。 Any other options to achieve the same? 还有其他选择可以达到相同目的吗? Thanks. 谢谢。

<span id="goog" style="display:none;" >
    <img height="14" width="14" src="static/images/ajax_load.gif" />
</span>

if(document.getElementById("goog")){
    alert('goog');
    document.getElementById("goog").style.display="none";
}

if(document.getElementById("goog")){
    alert('goog');
    document.getElementById("goog").style.display="inline";
}

Update : 03/07 更新:03/07

I have been trying to solve this for IE ,but I couldn't do it yet. 我一直在尝试为IE解决此问题,但目前还无法完成。

Problem: I am using the customized javascript tree component from dtree and to populate the data or children of every node clicked in the tree, I am using Ajax. 问题:我正在使用来自dtree的自定义javascript树组件,并填充树中单击的每个节点的数据或子节点,我正在使用Ajax。 Everytime,if something is being processed, I would like to show the ajax image(gif) along with the 'processing' text. 每次,如果正在处理某些内容,我想显示ajax image(gif)以及“处理中”文本。 Everything I tried works in Firefox but not in IE. 我尝试的所有内容都可以在Firefox中运行,但不能在IE中运行。 Each node is a div tag in the HTML document and is as below: 每个节点都是HTML文档中的div标签,如下所示:

<div class="dTreeNode">
<a href="javascript: d.o(1);">
    <img id="jd1" alt="" src="static/images/minusbottom.gif"/>
</a>
0
<input id="ch1" type="checkbox" onclick="javascript: changeCheckBoxValues(1);"/>
<a id="linkNode1" class="node" onclick="javascript: d.o(1); return false" href="#">AIG</a>
<span id="aj1" style="display: none;">
    <img height="14" width="14" src="static/images/ajax_load.gif"/>
</span>

When the Ajax request is fired, A static and previously undisplayed (display:none) is shown displayed, like below 触发Ajax请求时,将显示一个静态且先前未显示的内容(显示:无),如下所示

<table  align="center"  width="80%" border="1" cellspacing="0" cellpadding="0" id="proc"
        style="display:none;border-collapse: collapse; border: 1px solid; border-color: #D8D8D8;">
        <tr>
            <td width="33%"></td>
            <td class="buttonBar" width="33%">
                <span class="TextBlackNormal">&nbsp;&nbsp;&nbsp;&nbsp;processing </span>
            </td>
            <td width="33%"></td>
        </tr>
</table>

Both the anchor tags trigger the Ajax request, but the display (of the GIF Image and the processing text ) doesn't work only in IE. 这两个锚标记都触发了Ajax请求,但是(GIF图像和处理文本的)显示仅在IE中不起作用。

I had tried the following : 我尝试了以下方法:

1) interchanged the href & onclick values of the anchor tags in the DIV 2) visibility value of the DOM is tried instead of display 3) creating a dynamic DOM element and adding the image + text 4) innerHTML of the container (div / table ) where the ajax loading image + processing text is shown 1)在DIV中交换锚标记的href和onclick值2)尝试使用DOM的可见性值代替显示3)创建动态DOM元素并添加图像和文本4)容器(div /表)的innerHTML )显示ajax加载图像+处理文本的位置

I had figured out that it is not the Ajax call that is causing the issue, at least I think so. 我已经知道,导致此问题的不是Ajax调用,至少我是这么认为的。

When I experimented, with the conditional display of the image+text using display/visibility in IE, with some DOM value (value of text box) , It worked like a charm. 当我进行实验时,使用IE中的显示/可见性对图像+文本进行有条件的显示,并带有一些DOM值(文本框的值),它的工作原理很吸引人。

I am really not sure whats causing the issue. 我真的不确定是什么引起了问题。

Appreciate any help. 感谢任何帮助。

I think the question is a bit hard to understand. 我认为这个问题有点难以理解。 But the big question here is what IE version you are using. 但是这里最大的问题是您使用的是哪个IE版本。 Older versions of IE, have some rendering problems when hiding/showing elements. 较旧版本的IE在隐藏/显示元素时存在一些渲染问题。 To correct that fiddle around with position: relative and zoom: 1 . 要更正position: relativezoom: 1

But the script should work, but you might get an error in your AJAX call, which prevents you from calling your success function. 但是该脚本应该可以工作,但是您在AJAX调用中可能会出错,这将阻止您调用成功函数。 Try to add an error event and see if that gets triggered. 尝试添加一个错误事件,看看是否被触发。 Im not quite sure what you are recieving from the server, but IE can sometimes fail on elements that are blocked. 我不太确定您要从服务器接收什么,但是IE有时会在被阻止的元素上失败。

But a showcase in jsfiddle would be nice. 但是在jsfiddle中进行展示会很好。

document.getElementById in IE actually may return element with name="goog" . IE中的document.getElementById实际上可能返回name="goog"元素。 Also if you have several elements on page with such id, this is incorrect and different browsers may behave differently in such situation. 同样,如果页面上有多个具有此类ID的元素,则这是不正确的,在这种情况下,不同的浏览器可能会表现不同。 Perform checks like that in IE: 在IE中执行类似的检查:

alert(document.getElementById("goog").id);
alert(document.getElementById("goog").tagName);

您可以尝试“内联”更改“”或访问http://jsfiddle.net/xTUZd/2/

From the below quoted text, 在下面引用的文字中,

Problem: I am using the customized javascript tree component from dtree and to populate the data or children of every node clicked in the tree, I am using Ajax. 问题:我正在使用来自dtree的自定义javascript树组件,并填充树中单击的每个节点的数据或子节点,我正在使用Ajax。 Everytime,if something is being processed, I would like to show the ajax image(gif) along with the 'processing' text. 每次,如果正在处理某些内容,我想显示ajax image(gif)以及“处理中”文本。 Everything I tried works in Firefox but not in IE. 我尝试的所有内容都可以在Firefox中运行,但不能在IE中运行。 Each node is a div tag in the HTML document and is as below: 每个节点都是HTML文档中的div标签,如下所示:

i think u want display processing text until original data is fetched by ajax call. 我想你想显示处理文本,直到通过ajax调用获取原始数据。

If so then u can just use image to display by checking the ajax status, 如果是这样,那么您可以通过检查ajax状态来使用图像进行显示,

Have a div in every row(may be next to the anchor text horizontally) where u want to display the the processing text. 您要在其中显示处理文本的每一行中都有一个div(可能水平位于锚文本旁边)。

On the ajax callback function, 在ajax回调函数上,

xmlhttp.onreadystatechange=function()
{
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  }
  else
  {
     document.getElementById("goog").innerHTML ='<img src=static/images/ajax_load.gif>';
  }
}

I think this is enough for u? 我觉得这对你足够了吗? if i misunderstood your question, i'm sorry. 如果我误解了您的问题,对不起。

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

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