不在Netscape中工作:但它在IE和Firefox中 [英] Not working in Netscape: but it is in IE and firefox

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

问题描述

请帮忙!这是我完成目前工作的

网站之前的最后编码障碍。看起来这应该可行,但它不是b $ b。 (假设发生了什么:当你从下拉菜单中选择你想要的选项

时,相应的< div>变得可见)。我有一些警告来查看代码失败的地方,而对于Netscape中的一些

原因,它并没有完成序列。看起来好像很难修复...... b $ b应该很容易修复......唉!谢谢。


<! -

函数changeForm(what){

for(var i = 0; i< ; what.options.length; i ++)

{

alert(''选项数:''+ what.options.length)

if(what.options [i] .selected){

alert(''selected''+ i)

if(document.all){

alert(''看看document.all'')


document.all [what.options [i] .value] .style.visibility =" visible" ;;

}否则if(document.layers){

alert(''see document.layers'')

document.layers [what。 options [i] .value] .visibility =

" visible";

} else {

alert(''see none''' )


document.all [what.options [i] .value] .style.visibility =" visible";

}

} else {

alert(''deselect''+ i)

if(document.all){

alert(' '看到document.all'')


document.all [wh at.options [i] .value] .style.visibility =" hidden";

} else if(document.layers){

alert(''看到文件.layers'')

document.layers [what.options [i] .value] .visibility =

" hidden";

} else {

alert(''看不到'')


document.all [what.options [i] .value] .style.visibility = 隐藏;

}

}

}

}


// - >

< / script>


< / head>


< FORM>

< SELECT NAME =" selectList" onChange =" changeForm(this.form.selectList)"

< OPTION VALUE =" form1" SELECTED>问题1

< OPTION VALUE =" form2">问题2

< OPTION VALUE =" form3">问题3

< / SELECT>


< br>

< DIV STYLE =" position:absolute">

< / DIV>


< DIV ID =" form1" style =" position:absolute;能见度:可见;">

回答1

< / DIV>


< DIV ID ="窗口2" style =" position:absolute;可见性:隐藏;">

回答2

< / DIV>


< DIV ID =" form3" style =" position:absolute;可见性:隐藏;">

答案3 -

< / DIV>

Please help! This is the last coding hurdle before I am done with the
site I am presently working on. It seems like this should work, but it
isn''t. (What is suppose to happen: when you select the option you want
from the drop down menu the appropriate <div> becomes visible). I have
put in some alerts to see where the code is failing, and for some
reason in Netscape it isn''t completing the sequence. It seems like it
should be easy to fix... agh! Thank you.

<!--
function changeForm(what) {
for (var i=0; i<what.options.length; i++)
{
alert(''number of options: '' + what.options.length)
if (what.options[i].selected) {
alert(''selected '' + i)
if(document.all) {
alert(''sees document.all'')

document.all[what.options[i].value].style.visibility="visible";
} else if (document.layers){
alert(''sees document.layers'')
document.layers[what.options[i].value].visibility =
"visible";
} else {
alert(''sees none'')

document.all[what.options[i].value].style.visibility="visible";
}
} else {
alert(''deselect '' + i)
if(document.all) {
alert(''sees document.all'')

document.all[what.options[i].value].style.visibility="hidden";
} else if (document.layers){
alert(''sees document.layers'')
document.layers[what.options[i].value].visibility =
"hidden";
} else {
alert(''sees no'')

document.all[what.options[i].value].style.visibility="hidden";
}
}
}
}

//-->
</script>

</head>

<FORM>
<SELECT NAME="selectList" onChange="changeForm(this.form.selectList)">
<OPTION VALUE="form1" SELECTED>Question 1
<OPTION VALUE="form2">Question 2
<OPTION VALUE="form3">Question 3
</SELECT>

<br>
<DIV STYLE="position: absolute">
</DIV>

<DIV ID="form1" style="position: absolute; visibility: visible;">
Answer 1
</DIV>

<DIV ID="form2" style="position: absolute; visibility: hidden;">
Answer 2
</DIV>

<DIV ID="form3" style="position: absolute; visibility: hidden;">
Answer 3 -
</DIV>

推荐答案

2005年7月11日18:21, er***@telus.net 写道:


[snip]
On 11/07/2005 18:21, er***@telus.net wrote:

[snip]
看起来这应该有效,但事实并非如此。


所有系列都是微软发明的专有功能,并且由其他几个人实现了
。 Mozilla最近决定添加''silent''

支持以应对编写错误的代码,这些代码没有检查支持,

但盲目假设该集合可用。


通过''沉默'',我的意思是


if(document.all)


将在Firefox中失败。较旧版本的Mozilla软件将完全失败




解决方案是使用getElementById方法。除了两个条件之外的所有条件都应该避免所有

集合:


1)为不需要的浏览器提供getElementById仿真$ b支持它,但确实实现了所有集合。这只是

真的适用于IE4。

2)在IE5.x中为getElementsByTagName提供替换当

传递星号(*)为一个论点。这些版本将

总是返回一个空集合,而不是所有元素。


[snip]

<! -


删除它及其下面的结束分隔符。


if(!document.getElementById){

document .getElementById = function(){

返回null;

};

}


函数changeForm(what){

var f;


for(var i = 0,o = what.options,n = o.length; i< n; ++ i){

if(!(f = document.getElementById(o [i] .value))||!f.style){

return ;

}

f.style.display = o [i]。选择

? ''''

:''没有';

}

}


[ snip]

< SELECT NAME =" selectList"的onChange = QUOT; changeForm(this.form.selectList)">


只需:


< select name =" selectList" onchange =" changeForm(this);">


[snip]

< br>
< DIV STYLE =" ; position:absolute">
< / DIV>


删除它,

< DIV ID =" form1" style =" position:absolute; visibility:visible;">
It seems like this should work, but it isn''t.
The all collection is a proprietary feature invented by Microsoft, and
implemented by few others. Mozilla recently decided to add ''silent''
support to cope with badly written code which doesn''t check for support,
but blindly assumes the collection is available.

By ''silent'', I mean that

if(document.all)

will fail in Firefox. Older versions of Mozilla software will fail
completely.

The solution is to use the getElementById method instead. The all
collection should be avoided for all but two conditions:

1) Providing getElementById emulation for browsers that don''t
support it, but do implement the all collection. This only
really applies to IE4.
2) Providing a replacement for getElementsByTagName in IE5.x when
passing an asterisk (*) as an argument. These versions will
always return an empty collection, rather than all elements.

[snip]
<!--
Remove that and its closing delimiter, below.

if(!document.getElementById) {
document.getElementById = function() {
return null;
};
}

function changeForm(what) {
var f;

for(var i = 0, o = what.options, n = o.length; i < n; ++i) {
if(!(f = document.getElementById(o[i].value)) || !f.style) {
return;
}
f.style.display = o[i].selected
? ''''
: ''none'';
}
}

[snip]
<SELECT NAME="selectList" onChange="changeForm(this.form.selectList)">
Just:

<select name="selectList" onchange="changeForm(this);">

[snip]
<br>
<DIV STYLE="position: absolute">
</DIV>
Remove that,
<DIV ID="form1" style="position: absolute; visibility: visible;">




并使用display属性来控制是否呈现元素。你

然后可以删除位置声明。


[snip]


Mike


-

Michael Winter

使用[新闻]作为前缀主题后再回复电子邮件。



and use display property to control whether the element is rendered. You
can then remove the position declaration.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.

er***@telus.net 写道:
er***@telus.net wrote:
请帮忙!这是我完成目前工作的
网站之前的最后编码障碍。看起来这应该有效,但它不是。 (假设发生了什么:当你从下拉菜单中选择你想要的选项时,相应的< div>变得可见)。我已经发布了一些警报来查看代码失败的地方,并且出于Netscape的某些原因,它并没有完成序列。好像它应该很容易修复......唉!谢谢。


(不是NN4,但可以这样做):


函数changeForm(what){

var x;

if((x = document.getElementById(what.options [what.selectedIndex] .value)

&& x.style){

x.style.visibility = x.style.visibility ==" hidden"?" v isible":" hidden";

}

}


< SELECT NAME =" selectList" onChange =" changeForm(this)">

Mick

<! -
函数changeForm(what){
for(var i = 0; i< what.options.length; i ++)
{
alert(' '选项数量:''+ what.options.length)
if(what.options [i] .selected){
警告(''选择''+ i)
如果( document.all){
alert(''see document.all'')

document.all [what.options [i] .value] .style.visibility =" visible" ;
} if if(document.layers){
alert(''看看document.layers'')
document.layers [what.options [i] .value] .visibility =
" visible";
} else {
警告(''看不到'')

document.all [what.options [i] .value] .style.visibility =" visible";
}
} else {
alert(''deselect''+ i)
if(document.all){
alert(''see document.all'')

document.all [what.options [i] .value] .style.visibility =" hidden" ;;
} else if(document.layers){
alert(''看到文档.layers'')
document.layers [what.options [i] .value] .visibility =
" hidden";
} else {
alert(''see没有'')

document.all [what.options [i] .value] .style.visibility =" hidden";
}
}
}

// - >
< / script>

< / head>

< FORM>
< SELECT NAME =" selectList" onChange =" changeForm(this.form.selectList)">
< OPTION VALUE =" form1" SELECTED>问题1
< OPTION VALUE =" form2">问题2
< OPTION VALUE =" form3">问题3
< / SELECT>

< br>
< DIV STYLE =" position:absolute">
< / DIV>

< DIV ID =" form1的" style =" position:absolute;可见性:可见;">
答案1
< / DIV>

< DIV ID =" form2" style =" position:absolute;可见性:隐藏;">
答案2
< / DIV>

< DIV ID =" form3" style =" position:absolute;可见性:隐藏;">
答案3 -
< / DIV>
Please help! This is the last coding hurdle before I am done with the
site I am presently working on. It seems like this should work, but it
isn''t. (What is suppose to happen: when you select the option you want
from the drop down menu the appropriate <div> becomes visible). I have
put in some alerts to see where the code is failing, and for some
reason in Netscape it isn''t completing the sequence. It seems like it
should be easy to fix... agh! Thank you.
(not NN4, but it could be done):

function changeForm(what){
var x;
if((x=document.getElementById(what.options[what.selectedIndex].value)
&& x.style){
x.style.visibility=x.style.visibility=="hidden"?"v isible":"hidden";
}
}

<SELECT NAME="selectList" onChange="changeForm(this)">
Mick

<!--
function changeForm(what) {
for (var i=0; i<what.options.length; i++)
{
alert(''number of options: '' + what.options.length)
if (what.options[i].selected) {
alert(''selected '' + i)
if(document.all) {
alert(''sees document.all'')

document.all[what.options[i].value].style.visibility="visible";
} else if (document.layers){
alert(''sees document.layers'')
document.layers[what.options[i].value].visibility =
"visible";
} else {
alert(''sees none'')

document.all[what.options[i].value].style.visibility="visible";
}
} else {
alert(''deselect '' + i)
if(document.all) {
alert(''sees document.all'')

document.all[what.options[i].value].style.visibility="hidden";
} else if (document.layers){
alert(''sees document.layers'')
document.layers[what.options[i].value].visibility =
"hidden";
} else {
alert(''sees no'')

document.all[what.options[i].value].style.visibility="hidden";
}
}
}
}

//-->
</script>

</head>

<FORM>
<SELECT NAME="selectList" onChange="changeForm(this.form.selectList)">
<OPTION VALUE="form1" SELECTED>Question 1
<OPTION VALUE="form2">Question 2
<OPTION VALUE="form3">Question 3
</SELECT>

<br>
<DIV STYLE="position: absolute">
</DIV>

<DIV ID="form1" style="position: absolute; visibility: visible;">
Answer 1
</DIV>

<DIV ID="form2" style="position: absolute; visibility: hidden;">
Answer 2
</DIV>

<DIV ID="form3" style="position: absolute; visibility: hidden;">
Answer 3 -
</DIV>



Mike:

感谢您的澄清。由于某种原因,我仍然无法得到

的工作。脚本没有将隐藏更改为可见。如果我将它们设置为

全部可见它可以工作但是当页面首次启动时所有

''问题'出现。


< script language =" javascript">


if(!document.getElementById){

document.getElementById = function(){

返回null;

};

}


函数changeForm(what){

var f;


for(var i = 0,o = what.options,n = o.length; i< n; ++ i)<如果(!(f = document.getElementById(o [i] .value))||!f.style){

返回;

}

f.style.display = o [i]。选择

? ''''

:''没有';

}

}


< ; / script>


< / head>


< FORM>

< SELECT NAME = "选择列表的" onchange =" changeForm(this);">

< OPTION VALUE =" form1"已选择>选择一个问题

< OPTION VALUE =" form2">问题2

< OPTION VALUE =" form3">问题3
< / SELECT>


< DIV ID =" form1" style =" visibility:visible;">

答案1

< / DIV>


< DIV ID = QUOT;窗口2" style =" visibility:hidden;">

答案2

< / DIV>


< DIV ID = QUOT; form3" style =" visibility:hidden;">

答案3

< / DIV>

Mike:
Thanks for the clarification. For some reason I still cannot get it to
work. The script isn''t changing the hidden to visible. If I set them
all to visible it works but when the page is first launched all
''questions'' show up.

<script language="javascript">

if(!document.getElementById){
document.getElementById = function() {
return null;
};
}

function changeForm(what){
var f;

for(var i = 0, o = what.options, n = o.length; i < n; ++i)
{
if(!(f = document.getElementById(o[i].value)) || !f.style) {
return;
}
f.style.display = o[i].selected
? ''''
: ''none'';
}
}

</script>

</head>

<FORM>
<SELECT NAME="selectList" onchange="changeForm(this);">
<OPTION VALUE="form1" SELECTED>Select a question
<OPTION VALUE="form2">Question 2
<OPTION VALUE="form3">Question 3
</SELECT>

<DIV ID="form1" style="visibility: visible;">
Answer 1
</DIV>

<DIV ID="form2" style="visibility: hidden;">
Answer 2
</DIV>

<DIV ID="form3" style="visibility: hidden;">
Answer 3
</DIV>

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

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