GetElementByTagName,document.All& document.Layers - 这是怎么回事? [英] GetElementByTagName, document.All & document.Layers - What's up with that?

查看:63
本文介绍了GetElementByTagName,document.All& document.Layers - 这是怎么回事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



感谢您提前获得任何帮助...好吧,我已经在JS下面列出了要求显示(DIV)标签的
。 ..饼干

功能不包括在内,因为不觉得它是必要的,但你会得到这个想法!

函数closeall ()

{

var objs;


if(document.all)

{objs = document.all.tags(" DIV");

alert(''1all'')

}

else if(document .getElementsByTagName)

{objs = document.getElementsByTagName(" DIV");

alert(''1getElement'')

}

else if(document.layers)

{objs = document.layers [" DIV"];

alert(''1Layers'' )

}

其他

{alert(''对不起,您的浏览器不支持我们的主页

导航系统'');对于(var i = 0; i< objs.length; i ++){

if(objs [i] .className =" small")


{

objs [i] .style.display =" none" ;;

}

}

}


函数expandDiv(tahw){

setCookie(" thingsmenu",tahw,7);

closeall();


what = tahw +" _menu"


if(document.all(what)。 style.display =" none"){

document.all(what).style.display ="" ;;

alert(''2all'')

}

else if(document.getElementsByTagName(what).style.display =

" none"){

document.getElementsByTagName(what).style.display ="" ;;

alert(''2getElement'')

}

else {document.layers(what).style.display =" none" ;;

alert(''2layers'')

}
< br $>
}


函数setmenu()

{

var menuvar;

menuvar = getCookie(" thingsmenu");


expandDiv(menuvar) ;

}

这适用于IE和Firefox,但不适用于Netscape ...

警报的结果(用于调试)是如下


IE:1all - 2all

FireFox:1getElement - 2all

NS:1getElement - 然后什么都不返回!! br />

不相信Firefox是对的 - 为什么1getElement 2all?

无论如何它都有效..只需要让Netscape工作,任何想法?


欣赏它


---------------------------- ------------------

发布于NewsLeecher v2.0 Beta 5

* Binary Usenet Leching Made easy

* http://www.newsleecher.com/?usenet

---------------------------------------- ------

Hi,
Thanks for any help in advance... Okay, I have the JS listed
below that calls for the display of the (DIV) tag... cookie
function not included, as don''t feel its necessary but you''ll
get the idea!
function closeall()
{
var objs;

if (document.all)
{ objs = document.all.tags("DIV");
alert(''1all'')
}
else if (document.getElementsByTagName)
{ objs = document.getElementsByTagName("DIV");
alert(''1getElement'')
}
else if (document.layers)
{ objs = document.layers["DIV"];
alert(''1Layers'')
}
else
{ alert(''Sorry, Your browser does not support our Main
Navigation system''); }

for (var i=0; i<objs.length; i++) {
if (objs[i].className = "small")
{
objs[i].style.display = "none";
}
}
}

function expandDiv(tahw) {
setCookie("thingsmenu", tahw, 7);
closeall();

what = tahw + "_menu"

if (document.all(what).style.display = "none") {
document.all(what).style.display = "";
alert(''2all'')
}
else if (document.getElementsByTagName(what).style.display =
"none") {
document.getElementsByTagName(what).style.display = "";
alert(''2getElement'')
}
else { document.layers(what).style.display = "none";
alert(''2layers'')
}

}

function setmenu()
{
var menuvar;
menuvar = getCookie("thingsmenu");

expandDiv(menuvar);
}
This works both in IE and Firefox but not Netscape...
The results from the alerts (placed for debug) are as follows

IE: 1all - 2all
FireFox: 1getElement - 2all
NS: 1getElement - then returns nothing!!

Not convinced that Firefox is right - why 1getElement the 2all?
Anyhow it works.. just need to get Netscape working, any ideas?

Appreciate it

----------------------------------------------
Posted with NewsLeecher v2.0 Beta 5
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------

推荐答案



InvisibleMan写道:



InvisibleMan wrote:

else if(document.layers)
{objs = document.layers [" DIV"];


Netscape 4不允许你选择图层按标记名称的元素如此

这种方法可能会失败。


这在IE和Firefox中均有效,但在Netscape中无效...


究竟哪个Netscape版本? Netscape JavaScript

控制台说什么错误消息?


警报的结果(放置用于调试)如下
< IE:1all - 2all
FireFox:1getElement - 2all
NS:1getElement - 然后什么都不返回!!

不相信Firefox是对的 - 为什么1getElement是2all?


Firefox(至少1.0及更高版本)以及Mozilla 1.7.5及更高版本
quirks模式支持对document.all的未经检查的访问,因此


if(document.all(what).style.display =" none"){

document.all(what).style.display =" ;" ;;

alert(''2all'')

}


将执行。

无论如何它都有效..只需要让Netscape工作,任何想法?
else if (document.layers)
{ objs = document.layers["DIV"];
Netscape 4 doesn''t allow you to select "layer" elements by tagname so
that approach is likely to fail.

This works both in IE and Firefox but not Netscape...
Which Netscape version exactly? What does the Netscape JavaScript
console say, any error messages?

The results from the alerts (placed for debug) are as follows

IE: 1all - 2all
FireFox: 1getElement - 2all
NS: 1getElement - then returns nothing!!

Not convinced that Firefox is right - why 1getElement the 2all?
Firefox (at least 1.0 and later) as well as Mozilla 1.7.5 and later in
quirks mode supports unchecked access to document.all thus the

if (document.all(what).style.display = "none") {
document.all(what).style.display = "";
alert(''2all'')
}

will execute.
Anyhow it works.. just need to get Netscape working, any ideas?




Netscape 7.2基于Mozilla 1.7.2并且有document.all

支持不存在因此表达式

document.all(what).style.display

会出现脚本错误。

所以你需要正确检查

if(document.all){

//使用document.all这里

}

else if(document.getElementsByTagName){

//使用document.getElementsByTagName

}

或其他任何集合或者你想要使用的方法。


-


Martin Honnen
http://JavaScript.FAQTs.com/


InvisibleMan写道:
InvisibleMan wrote:

谢谢提前任何帮助...好吧,我有下面列出的JS,要求显示(DIV)标签...饼干
功能不包括在内,因为我觉得它没有必要但你会得到这个想法!

函数closeall()
{var /> var objs;

if(文件。所有)
{objs = document.all.tags(" DIV");
alert(''1all'')
}
if if(document.getElementsByTagName)
{objs = document.getElementsByTagName(" DIV");
alert(''1getElement'')


我会交换这些并执行document.getElementsByTagName

优先。这将包括大部分的IE和几乎所有的东西

else。 document.all将选择旧的IE浏览器。


我现在不在IE附近,但我也认为IE更喜欢方格

的文档括号。所有,不是圆的:


{objs = document.all.tags [" DIV"];

}
if if(document。层)
{objs = document.layers [" DIV"];
alert(''1Layers'')
}

{alert(''对不起,您的浏览器不支持我们的主要导航系统''); }


此消息也是向后的 - 您的''主导航系统''

不支持用户浏览器。如果你告诉他们你支持哪些浏览器并提供

的链接从哪里获取它们将会很有帮助。

for(var i = 0; i< objs.length; i ++){
if(objs [i] .className =" small")


这将设置objs [i] .className为small,因此测试将

总是成功,并且所有div的类名都设置为

" small"并且显示设置为无。你打算写一下:


if(objs [i] .className ==" small)

{
objs [i] .style.display =" none";
}
}

函数expandDiv(tahw){
setCookie(" thingsmenu", tahw,7);
closeall();

what = tahw +" _menu"

if(document.all(what).style.display = 没有){


这里再次说明,你没有使用比较而是作业。

你的意思是:

if(document.all [what] .style.display ==" none"){

document.all(what).style.display ="" ;; <如果(document.getElementsByTagName(what).style.display =
" none"){


又一次......

document.getElementsByTagName(what).style.display ="" ;;
alert(''2getElement'')
}
else {document.layers(what).style.display =" none";
alert(''2layers'')
}

}

功能setmenu()
{
var menuvar;
menuvar = getCookie(" thingsmenu");


这可能是:


var menuvar = getCookie(" thingsmenu");

expandDiv(menuvar );
}

这适用于IE和Firefox,但不适用于Netscape ......
警报(放置用于调试)的结果如下
< IE:1all - 2all
FireFox:1getElement - 2all
NS:1getElement - 然后什么都不返回!!

不相信Firefox是对的 - 为什么1getElement是2all?


因为你的测试不是测试,而是一项任务,

永远是真的,而不是2getElement

无论如何它都有效..
Hi,
Thanks for any help in advance... Okay, I have the JS listed
below that calls for the display of the (DIV) tag... cookie
function not included, as don''t feel its necessary but you''ll
get the idea!
function closeall()
{
var objs;

if (document.all)
{ objs = document.all.tags("DIV");
alert(''1all'')
}
else if (document.getElementsByTagName)
{ objs = document.getElementsByTagName("DIV");
alert(''1getElement'')
I would swap these around and do document.getElementsByTagName
first. That will include most of IE and just about everything
else. document.all will pick up older IE.

I''m not near IE right now, but I also think IE prefers square
brackets for document.all, not round:

{ objs = document.all.tags["DIV"];
}
else if (document.layers)
{ objs = document.layers["DIV"];
alert(''1Layers'')
}
else
{ alert(''Sorry, Your browser does not support our Main
Navigation system''); }
This message is also backward - your ''Main Navigation system''
does not support the users browser. It would be helpful if you
told them which browsers you do support and offered links on
where to get them from.

for (var i=0; i<objs.length; i++) {
if (objs[i].className = "small")
This will set objs[i].className to "small", so the test will
always succeed and all divs will have their classname set to
"small" and display set to ''none''. Did you meant to write:

if (objs[i].className == "small")
{
objs[i].style.display = "none";
}
}
}

function expandDiv(tahw) {
setCookie("thingsmenu", tahw, 7);
closeall();

what = tahw + "_menu"

if (document.all(what).style.display = "none") {
Here again, you are not using a comparison but an assignment.
Did you mean:

if (document.all[what].style.display == "none") {
document.all(what).style.display = "";
alert(''2all'')
}
else if (document.getElementsByTagName(what).style.display =
"none") {
and again...
document.getElementsByTagName(what).style.display = "";
alert(''2getElement'')
}
else { document.layers(what).style.display = "none";
alert(''2layers'')
}

}

function setmenu()
{
var menuvar;
menuvar = getCookie("thingsmenu");
This could be:

var menuvar = getCookie("thingsmenu");

expandDiv(menuvar);
}
This works both in IE and Firefox but not Netscape...
The results from the alerts (placed for debug) are as follows

IE: 1all - 2all
FireFox: 1getElement - 2all
NS: 1getElement - then returns nothing!!

Not convinced that Firefox is right - why 1getElement the 2all?
Because your "test" was not a test but an assignment that will
always be true and not get to "2getElement"
Anyhow it works..




你认为它有效 - 它不会做你认为它正在做的事情。

-

Fred



You think it works - it doesn''t do what you think it''s doing.
--
Fred


我正在使用NS7.2 - 我知道该脚本适用于NS6 ...

真的希望这适用于大多数浏览器版本(或者考虑到各种变化,可以考虑多少




是NS4 getElemenyByID - 我认为响起一些如何...

只是阅读你的其余部分,并且不确定如何

impliment ...大脑被炒这个年龄只是为了得到它

它是...


欣赏信息


------------------ ----------------------------

发布于NewsLeecher v2.0 Beta 5

* Binary Usenet Leeching Made

* http://www.newsleecher.com/?usenet

------------- ---------------------------------

I''m using NS7.2 - I know that the script did work on NS6...
Really want this to work on most Browser version (or as many as
possible considering the variations)

is NS4 getElemenyByID - i think that rings bells some how...

Just reading the rest of your reply and not sure quite how to
impliment... brain is fried with this to ages just to get it where
it is...

Appreciate the info

----------------------------------------------
Posted with NewsLeecher v2.0 Beta 5
* Binary Usenet Leeching Made Easy
* http://www.newsleecher.com/?usenet
----------------------------------------------


这篇关于GetElementByTagName,document.All&amp; document.Layers - 这是怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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