IE6不会隐藏动态创建的span元素 [英] IE6 won't hide dynamically created span elements

查看:47
本文介绍了IE6不会隐藏动态创建的span元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有几个动态生成列表的小表格

框。当用户从第一个框中进行选择时,第二个

框将刷新。当他们从第二个框中做出选择时,我将
连接两个框中的选项,并使用createElement将字符串添加到表单顶部的

列表中和appendChild。

列表实际上是div中包含的一堆span元素。每个

span元素包含一个红色X的小图形,用户可以点击从列表中删除该项目。


所有这些在Mozilla和Opera中运行得很好,但是 - 等待它 -

删除功能在IE中失败,抛出需要对象

这行错误:


this.style = document.getElementById(nm).style;


其中nm是范围的ID元素我试图隐藏,通过设置

它的显示属性为无。


什么是真正有趣的事实上,当表单首次加载时,我在该div中有一个或多个span

元素,IE将隐藏这些基于HTML的元素而不会抱怨。这只是我在飞行中产生的跨度,它隐藏着一个问题。


我的方式一定有问题创造那些动态跨度,你说b $ b b?也许是这样,但IE确实显示它们没问题,并且代码全部

在其他两个浏览器中运行良好。现在我不是javascript老手,无论如何都是
,但这在我看来是IE中的一个错误。我在这里询问

是否有人知道这方面的解决方法,或者更好的方法来完成我想要做的事情。


提前致谢,

Blake Couch

Javascript Noob

I have a little form with a couple of dynamically generated list
boxes. When the user makes a selection from the first box, the second
box is refreshed. When they make a selection from the second box, I
concatenate the selections from the two boxes and add the string to a
list at the top of the form, using createElement and appendChild. The
list is actually a bunch of span elements contained within a div. Each
span element includes a small graphic of a red X, which the user can
click to delete that item from the list.

All of this works just fine in Mozilla and Opera, but - wait for it -
the delete functionality fails in IE, throwing an "Object Required"
error on this line:

this.style = document.getElementById(nm).style;

where nm is the ID of the span element I''m trying to hide, by setting
it''s display property to "none."

What''s really interesting is the fact that I have one or more span
elements in that div when the form first loads, and IE will hide these
HTML-based elements without complaining. It''s only the spans that I
generate on the fly that it has a problem hiding.

Must be something wrong with the way I''m creating those dynamic spans,
you say? Maybe so, but IE does display them okay, and the code all
works great in the other two browsers. Now I''m no javascript veteran,
by any means, but this appears to me to be a bug in IE. What I asking
here is whether anybody knows of a workaround for this, or maybe a
better way of accomplishing what I''m trying to do.

Thanks in advance,
Blake Couch
Javascript Noob

推荐答案

Nicholas Couch写道:

Nicholas Couch wrote:

this.style = document.getElementById(nm).style;
this.style = document.getElementById(nm).style;




那应该是''nm''...


this.style = document.getElementById(''nm'')。风格;


我只能在没有真正查看代码的情况下猜测这是你的问题。



That should be ''nm'' ...

this.style = document.getElementById(''nm'').style;

I can only guess that''s your problem without actually looking at the code.


Nicholas Couch写道:

[snip] ]
Nicholas Couch wrote:
[snip]
所有这些在Mozilla和Opera中运行得很好,但是 - 等待它 -
删除功能在IE中失败,抛出Object Required
错误这一行:

this.style = document.getElementById(nm)。样式;

其中nm是我试图隐藏的span元素的ID,通过设置
它的显示属性为none。
All of this works just fine in Mozilla and Opera, but - wait for it -
the delete functionality fails in IE, throwing an "Object Required"
error on this line:

this.style = document.getElementById(nm).style;

where nm is the ID of the span element I''m trying to hide, by setting
it''s display property to "none."



[snip]


您可以尝试将元素放入< div>而不是

< span> - 我认为效果是一样的,你可以从div获得更多的

功能。尝试类似的事情:


divRef.style.display =''none'';


其中divRef是对你想要的div的引用隐藏。


我尝试了以上,它在Safari和IE 5.2上工作得很好

Mac - 在Windows上无法保证IE,但我做了一个类似的

对于使用div的Windows来说它运行正常。


干杯,Rob


[snip]

You could try putting your elements inside <div> rather than
<span> - I think the effect is the same and you have much more
functionality available from divs. Try something like:

divRef.style.display=''none'';

where divRef is a reference to the div you want to hide.

I tried the above, it worked fine in Safari and IE 5.2 on
Mac - no guarantee for IE on Windows but I have done a similar
thing for Windows using divs and it works fine.

Cheers, Rob


Nicholas Couch写道:

< snip>
Nicholas Couch wrote:
<snip>
你说,创造那些动态跨度的方式一定有问题吗?


是的。

也许是这样,但IE确实显示它们没问题,并且
代码在其他两个浏览器中都运行良好。


所以它不是100%的错误。

现在我不是javascript老手,无论如何,


显然,因为没有多少经验可以解决,为了调试代码,人们需要能够看到它。

但这个在我看来是IE中的一个错误。


什么是带有错误的网络浏览器? ;)

我在这里问的是,是否有人知道这是一个解决方法,


它可能不需要解决方法。跨浏览器代码可能足够
足够。

或者更好的方式来完成我想要做的事情。
Must be something wrong with the way I''m creating those
dynamic spans, you say?
Yes.
Maybe so, but IE does display them okay, and the
code all works great in the other two browsers.
So it is not 100% faulty.
Now I''m no javascript veteran, by any means,
Obviously, as it doesn''t take much experience to work out that in order
to debug code people need to be able to see it.
but this appears to me to be a bug in IE.
What, a web browser with a bug? ;)
What I asking here is whether anybody knows of
a workaround for this,
It probably doesn''t need a workaround. Cross browser code would probably
suffice.
or maybe a better way
of accomplishing what I''m trying to do.




你想要做什么(至少克服你想要做的事)

在IE浏览器中成功运行。


Richard。



What you are trying to do (at least claming that you are trying to do)
works successfully in IE browsers.

Richard.


这篇关于IE6不会隐藏动态创建的span元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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