在ie和opera中工作不是mozilla [英] Works in ie and opera not mozilla

查看:68
本文介绍了在ie和opera中工作不是mozilla的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码在ie和opera中运行良好,但在Mozilla中根本没有。

任何人都知道如何正确使用它?


<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 Transitional // EN">

< script language =" JavaScript" type =" text / javascript">

函数显示(那)

{

if(box.style.visibility ==' 'hidden''){that.style.visibility =

''visible''};

}

< / script>

< html>

< head>

< title> Untitled< / title>

< / head>

< body>

< div style =" width:100px;身高:100px;边框:1px纯黑色;

background-color:Aqua;" onclick =" show(box)"> help< / div>

< div id =" box"风格= QUOT;位置:相对;宽度:100px;身高:100px;

边框:1px纯黑色;背景色:Aqua;能见度:

隐藏;"> me< / div>

< / body>

< / html>


谢谢


Tony Kulik

This code works fine in ie and opera but not at all in Mozilla.
Anybody got a clue as to how to get it right?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script language="JavaScript" type="text/javascript">
function show(that)
{
if (box.style.visibility==''hidden'') { that.style.visibility =
''visible''};
}
</script>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<div style="width: 100px; height: 100px; border: 1px solid Black;
background-color: Aqua;" onclick="show(box)">help</div>
<div id="box" style=" position: relative; width: 100px; height: 100px;
border: 1px solid Black; background-color: Aqua; visibility:
hidden;">me</div>
</body>
</html>

Thanks

Tony Kulik

推荐答案

嗯我很惊讶完全可以工作。

你调用它作为onClick =" show(box)"。

现在我们有两个问题:作为框调用,不是即使在

引号之间,该对象仍然会触发错误:box不是某个定义的某个全局变量 - 并且你同意yopu从未定义过这样的

通过脚本变量。


然而它有效,所以唯一可行的原因就是那个单词,盒子,

处理为如果它是一个全局定义的变量,你没有定义。没有

出路。

所以脚本引擎必须将它分配给窗口对象:实际上

在IE上:

onClick =" show(window.box)"可以工作但是

onClick =" show(document.box)"没有。

所以发动机做了你的事。


现在,我希望你意识到这个赋值给窗口对象了

变量命名框是一个编程,脚本引擎显然是在做b / b
,但它不应该这样做 - 因此Mozilla拒绝了这个事实

(而不是正确_perhaps_我们可以说)解析它:实际上Netscape 7

错误说(这证明了我的观点):框未定义。也就是说,NS 7

同意该调用将隐含一个全局定义的变量

由你通过脚本而不是通过dom存在。


现在,我建议你改变那。它在IE上工作的事实可以仅仅归结为这样:DOM引擎在全球环境中存储

作为全局定义变量的图层名称 - 这是相当的

令人惊讶。也许有些人已经熟悉了这一点,但是Netscape 7报告的错误

也证明了这种行为很奇怪,虽然

有用但可以这样贴上标签,就像怪异一样至少可以说。


运行该语句并使其在任何地方都能正常工作的正确方法是:


onClick =" show( document.getElementById(''box''))"。

注意盒子周围的单个顶点:''盒子''


PS请更改:

if(box.style.visibility ==''hidden''){that.style.visibility = ...

更加一致:

if(that.style.visibility ==''hidden''){that.style.visibility = ...


namley change''box''into ''那'或NS7错误会持续存在,

ciao

Alberto
http://www.unitedscripters.com/

" tony kulik" < TK ******* @ ackulik.com> ha scritto nel messaggio

新闻:3f *************** @ news1.news.adelphia.net ...
Uhm I am surprised it works at all.
You invoke it as onClick="show(box)".
Now we have two issues there: calling in as box, that is not even in between
quotes, the object should have triggered an error anyway: box is not a
global variable somewhere defined - and you agree yopu never defined such a
variable via script.

Yet it works, so the only reason it can work is that that word, box, is
handled as if it were a globally defined variable that you didn''t define. NO
way out.
So the scripting engine must be assigning it to the window object: in fact
on IE:
onClick="show(window.box)" works but
onClick="show(document.box)" doesn''t.
So the engine did a thing ON YOUR BEHALF.

Now, I hope you realize that this assignment to the window object of the
variable named box is an assignment that the scripting engine is clearly
doing, yet it was _not_ supposed to do it - thence the fact Mozilla refuses
(rather "correctly" _perhaps_ we can say) to parse it: in fact Netscape 7
error says (which proves my point): "box is not defined". That is, NS 7
"agrees" that that call would have implied a globablly defined variable
being put into existance by you via script not via dom.

Now, I suggest to you to change that. The fact on IE it works can be
ascribed only to this: the DOM engine stores in a global environment the
names of the layers as globally defined variables - this is rather
surprising. Maybe some are already familiar with this, but the errors
reported by Netscape 7 too prove that this behaviour is weird, and though
helpful can be labeled as such, as weird to say the least.

The correct way to run that statement and make it work everywhere is this:

onClick="show(document.getElementById(''box''))".
note the single apex around box: ''box''

PS please change also:
if (box.style.visibility==''hidden'') { that.style.visibility =...
into a more consistent:
if (that.style.visibility==''hidden'') { that.style.visibility =...

namley change ''box'' into ''that'' or the NS7 error would persist,
ciao
Alberto
http://www.unitedscripters.com/

"tony kulik" <tk*******@ackulik.com> ha scritto nel messaggio
news:3f***************@news1.news.adelphia.net...
这个代码在ie和opera中运行良好,但在Mozilla中根本没有。
任何人都知道如何正确使用它?

<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 Transitional // EN">
< script language =" JavaScript" type =" text / javascript">
function show(that)
{
if(box.style.visibility ==''hidden''){that.style.visibility =
''可见''};
}
< / script>
< html>
< head>
< title> Untitled< ; / title>
< / head>
< body>
< div style =" width:100px;身高:100px;边框:1px实心黑色;
背景颜色:Aqua;" onclick =" show(box)"> help< / div>
< div id =" box"风格= QUOT;位置:相对;宽度:100px;高度:100px;
边框:1px纯黑色;背景色:Aqua;能见度:
隐藏;">我< / div>
< / body>
< / html>

谢谢

This code works fine in ie and opera but not at all in Mozilla.
Anybody got a clue as to how to get it right?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script language="JavaScript" type="text/javascript">
function show(that)
{
if (box.style.visibility==''hidden'') { that.style.visibility =
''visible''};
}
</script>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<div style="width: 100px; height: 100px; border: 1px solid Black;
background-color: Aqua;" onclick="show(box)">help</div>
<div id="box" style=" position: relative; width: 100px; height: 100px;
border: 1px solid Black; background-color: Aqua; visibility:
hidden;">me</div>
</body>
</html>

Thanks

Tony Kulik



tony kulik说:
tony kulik said:

此代码在ie和歌剧,但在Mozilla中根本没有。
任何人都知道如何正确使用它?

<!DOCTYPE HTML PUBLIC" - // W3C // DTD HTML 4.01 Transitional // EN">
< script language =" JavaScript" type =" text / javascript">
function show(that)
{
if(box.style.visibility ==''hidden''){that.style.visibility =
''visible''};
}
< div style =" width:100px;身高:100px;边框:1px实心黑色;
背景颜色:Aqua;" onclick =" show(box)"> help< / div>

This code works fine in ie and opera but not at all in Mozilla.
Anybody got a clue as to how to get it right?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<script language="JavaScript" type="text/javascript">
function show(that)
{
if (box.style.visibility==''hidden'') { that.style.visibility =
''visible''};
} <div style="width: 100px; height: 100px; border: 1px solid Black;
background-color: Aqua;" onclick="show(box)">help</div>




允许您访问< DIV> id为box的使用那个

的快捷方式被许多人认为是危险的,其中一些人写了浏览器规格。


功能显示(那个) {

if(document.getElementById(" box")。s​​tyle.visibility ==" hidden"){

document.getElementById(that).style.visibility =" vi sible";

}

}


onclick =" show(''box'')" ;


目前尚不清楚为什么你有盒子在一个案例中硬编码,但是

将其作为参数传递到另一个案例中,或者为什么你检查

看看它是否隐藏在使其可见之前。



Allowing you to access the <DIV> with id "box" using that
shortcut is considered dangerous by many people, some of
whom write browser specifications.

function show(that){
if (document.getElementById("box").style.visibility== "hidden"){
document.getElementById(that).style.visibility="vi sible";
}
}

onclick="show(''box'')"

It''s not clear why you have "box" hard-coded in one case, but
pass it in as an argument in the other, or why you check to
see if it is hidden before making it visible.


tony kulik写道:
tony kulik wrote:
这段代码在ie和opera中运行良好,但在Mozilla中根本没有。
任何人都知道如何正确使用它?
[...]
功能展示(那)
{
if(box.style.visibility = =''hidden''){that.style.visibility =
''visible''};
}
[...]
< div style ="宽度:100px;身高:100px;边框:1px实心黑色;
背景颜色:Aqua;" onclick =" show(box)"> help< / div>
< div id =" box"风格= QUOT;位置:相对;宽度:100px;高度:100px;
边框:1px纯黑色;背景色:Aqua;可见性:
隐藏;">我< / div>
[...]
This code works fine in ie and opera but not at all in Mozilla.
Anybody got a clue as to how to get it right?
[...]
function show(that)
{
if (box.style.visibility==''hidden'') { that.style.visibility =
''visible''};
}
[...]
<div style="width: 100px; height: 100px; border: 1px solid Black;
background-color: Aqua;" onclick="show(box)">help</div>
<div id="box" style=" position: relative; width: 100px; height: 100px;
border: 1px solid Black; background-color: Aqua; visibility:
hidden;">me</div>
[...]




只有IE使用'id'创建元素'自动属性

全局(窗口)对象(具有相同的标识符。)使用适合于DOM的DOM的方法引用`div''

元素相反,UA。

http://pointedears.de .vu / scripts / dhtml.js 可以帮助您以这种方式简化您的

代码并使其在已知的具有DHTML功能的用户代理中工作,价格相同

时间。请参阅 http://pointedears.de.vu/scripts/test/whatami pp。了解详情。


如果你使用'box'',你不需要

中的'那''命名参数你的方法。或者,如果您需要该方法的参数来提供一般的

目的,那么`box.style.visibility''应该是`that.style.visibility''。 BTW:

对于Netscape 4.x,你应该使用CSS类和`class''属性

而不是'style''属性。

HTH


PointedEars



Only IE makes elements with `id'' attributes automagically properties of
the global (window) object (with the same identifier.) Reference the `div''
element using the methods appropriate to the DOM of the UA instead.

http://pointedears.de.vu/scripts/dhtml.js can help you in simplifying your
code that way and keep it working in known DHTML capable user agents at the
same time. See http://pointedears.de.vu/scripts/test/whatami pp. for details.

And if you use `box'' anyway you don''t need the `that'' named argument in
your method. Or if you need that argument for the method to serve a general
purpose that `box.style.visibility'' should be `that.style.visibility''. BTW:
For Netscape 4.x you should use CSS classes and the `class'' attribute
instead of the `style'' attribute.
HTH

PointedEars


这篇关于在ie和opera中工作不是mozilla的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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