style.display不能在Firefox,Opera,Safari中使用 - IE7 OK [英] style.display not working in Firefox, Opera, Safari - IE7 OK

查看:163
本文介绍了style.display不能在Firefox,Opera,Safari中使用 - IE7 OK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绝对定位 div ,我想在用户点击链接时显示。链接的 onclick 调用一个js函数,设置要阻止的div的显示(也尝试:, inline table-cell inline-table 等)。这在IE7中工作的很好,而不是在所有其他浏览器我尝试过(FF2,FF3,Opera 9.5,Safari)。



并且调用后,它们显示显示已从 none 更改为,但



我可以得到 div 如果我改变显示值使用Firebug的HTML检查器(但不是通过Firebug的控制台运行javascript) - 所以我知道它不只是显示在屏幕等。






  • 使用不同的doctype(XHTML 1,HTML 4等)

  • 使用可见性/隐藏而不是显示块/无

  • 使用内联JavaScript代替函数调用

  • 不同的机器



有什么可能导致这种情况的想法?

解决方案

由于使用javascript设置属性从来没有工作,但使用Firebug的检查设置,我开始怀疑javascript ID选择器被打破 - 也许在DOM中有多个项目具有相同的ID ?源没有显示有,但循环遍历所有的div使用javascript我发现,这是这样。下面是我最终用来显示弹出窗口的函数:

  function openPopup(popupID)
{
var divs = getObjectsByTagAndClass('div','popupDiv');
if(divs!= undefined&& divs!= null)
{
for(var i = 0; i< divs.length; i ++)
{
if(divs [i] .id == popupID)
divs [i] .style.display ='block';
}
}
}

(实用函数getObjectsByTagAndClass未列出)



理想情况下,我会找出为什么相同的项目被多次插入,但我不能控制渲染平台,只是其输入。 p>

因此,在调试此类问题时,请记住检查DOM中的重复ID,这样可能会破坏getElementById



对所有回答的人,感谢您的帮助!


I have an absolutely positioned div that I want to show when the user clicks a link. The onclick of the link calls a js function that sets the display of the div to block (also tried: "", inline, table-cell, inline-table, etc). This works great in IE7, not at all in every other browser I've tried (FF2, FF3, Opera 9.5, Safari).

I've tried adding alerts before and after the call, and they show that the display has changed from none to block but the div does not display.

I can get the div to display in FF3 if I change the display value using Firebug's HTML inspector (but not by running javascript through Firebug's console) - so I know it's not just showing up off screen, etc.

I've tried everything I can think of, including:

  • Using a different doctype (XHTML 1, HTML 4, etc)
  • Using visibility visible/hidden instead of display block/none
  • Using inline javascript instead of a function call
  • Testing from different machines

Any ideas about what could cause this?

解决方案

Since setting the properties with javascript never seemed to work, but setting using Firebug's inspect did, I started to suspect that the javascript ID selector was broken - maybe there were multiple items in the DOM with the same ID? The source didn't show that there were, but looping through all divs using javascript I found that that was the case. Here's the function I ended up using to show the popup:

function openPopup(popupID)
{
  var divs = getObjectsByTagAndClass('div','popupDiv');
  if (divs != undefined && divs != null)
  {
    for (var i = 0; i < divs.length; i++)
    {
      if (divs[i].id == popupID)
        divs[i].style.display = 'block';        
    }
  }
}

(utility function getObjectsByTagAndClass not listed)

Ideally I'll find out why the same item is being inserted multiple times, but I don't have control over the rendering platform, just its inputs.

So when debugging issues like this, remember to check for duplicate IDs in the DOM, which can break getElementById.

To everyone who answered, thanks for your help!

这篇关于style.display不能在Firefox,Opera,Safari中使用 - IE7 OK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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