样式显示在Firefox,Opera,Safari中不起作用-(IE7正常) [英] Style display not working in Firefox, Opera, Safari - (IE7 is OK)

查看:106
本文介绍了样式显示在Firefox,Opera,Safari中不起作用-(IE7正常)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绝对定位的 div ,我想在用户单击链接时显示它。链接的 onclick 调用一个js函数,该函数将div的显示设置为阻止(也尝试:, inline 表单元格内联表等)。



在IE7中,此功能在IE7中非常有效,而在我尝试过的其他所有浏览器(FF2,FF3,Opera 9.5,Safari)中都没有。并在通话后显示,显示已从变为阻止,但 div 不显示。



我可以将 div 显示在FF3中如果我使用Firebug的HTML检查器更改了显示值(而不是通过Firebug的控制台运行javascript)-因此我知道它不仅显示在屏幕外,等等。



我尝试了所有我能想到的一切,包括:




  • 使用其他文档类型(XHTML 1,HTML 4等)

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

  • 使用内联javascript而不是函数调用

  • 测试来自不同的机器



关于可能导致这种情况的任何想法?

解决方案

自设置使用javascript的属性似乎从未起作用,但是使用Firebug的inspect进行设置后,我开始怀疑javascript ID选择器已损坏-可能在DOM中有多个具有相同ID的项目吗?消息来源没有表明有,但是使用JavaScript遍历了所有div,我发现情况确实如此。这是我最终用来显示弹出窗口的函数:

  function openPopup(popupID)
{
var divs = getObjectsByTagAndClass('div','popupDiv');
if(divs!= undefined&& divs!= null)
{
for(var i = 0; 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!

这篇关于样式显示在Firefox,Opera,Safari中不起作用-(IE7正常)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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