javascript通过id控制显示div问题(ducument.getElementById().style.display)

来源:百度知道 编辑:UC知道 时间:2024/05/29 07:49:53
为什么如下操作会提示object required错误?
<SCRIPT language="javascript">
var itemsshow_first = new Array("a1","a2","a3");
var itemsshow_second = new Array("b1","b2","b3");
if(){
showitem(itemsshow_second,itemsshow_first);
}else{
showitem(itemsshow_first,itemsshow_second);
}
function showitem(array_hidden,array_show)
{
var length_hidden = array_hidden.length;
var length_show = array_show.length;
var i,j;
for( i = 0;i < length_hidden;i++ )
{
//alert(array_hidden[i]);
document.getElementById(array_hidden[i]).style.display="None";
}
for( j = 0;j < length_show;j++ ){
document.getElementById(array_show[j]).style.display="";
}
}
</SCRIPT>
而如下做却没有问题?数组里存的不就是string型的吗?alert能够得到相应的字段……
<SCRIPT language="javascript">
if(){
document.getElementById("a

哈哈,是美女发的问题怎么说也要回答咯。
<SCRIPT LANGUAGE="JavaScript">
<!--
var itemsshow_first = new Array("a1","a2","a3");
var itemsshow_second = new Array("b1","b2","b3");
function $(el){return document.getElementById(el)}
if(condition)
{
for(var o in itemsshow_first)
$(itemsshow_first[o]).style.display="";
for(var o in itemsshow_second)
$(itemsshow_second[o]).style.display="none";
}
else
{
for(var o in itemsshow_first)
$(itemsshow_first[o]).style.display="none";
for(var o in itemsshow_second)
$(itemsshow_second[o]).style.display="";
}
//-->
</SCRIPT>
试试这个吧。哈哈跟据你第二种想法做的。