日期:2014-05-16  浏览次数:20318 次

缺少对象
<tr>
<TD>
<IMG   src= "images/2.jpg "   onclick   =   "showDiv( 'div_used ') "   > <IMG   src= "images/3.jpg "   onclick   =   "showDiv( 'div_current ') "> 2。当点击这两个图片时,再显示div里的图片。现在这行老是报错“缺少对象”
</TD>
</tr>
<tr>
<td>
<div   id   =   "div_current "   style   =   "display:block; "> <img   src= "images/banner.jpg "> 1。进入该html页时,先显示该图片。
</div>
<div   id   =   "div_used "   style   =   "display:none; "> <img   src   =   "images/4.jpg ">
</div>
</td>
</tr>
*********************************
3。JS
function   showDiv(divID)
{
var   id   =   document.getElementById(divID);
if(id   ==   'div_current ')
{
div_current.style.display   ==   "block ";
div_used.style.display   ==   "none ";
}
else
{
div_used.style.display   ==   "block ";
div_current.style.display   ==   "none ";
}
}

请大家帮帮忙,谢谢。

------解决方案--------------------
function showDiv(divID)
{
if(divID == 'div_current ')
{
div_current.style.display == "block ";
div_used.style.display == "none ";
}
else
{
div_used.style.display == "block ";
div_current.style.display == "none ";
}
}
------解决方案--------------------
var id = document.getElementById(divID);
if(id == 'div_current ')
这句话有问题啊!
你定义的id是一个object,而div_current看样子是个变量
------解决方案--------------------
id = document.getElementById(divID)得到的是一个对象,不能与字符串比较
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<title> Untitled Page </title>
</head>
<body>
<table>
<tr>
<td style= "width: 398px; height: 136px "> div_used
<img src= "images/2.jpg " onclick= "showDiv( 'div_used ') " height= "50 " width= "50 "> </td>
<td style= "width: 398px; height: 136px "> div_current
<img src= "images/3.jpg " onclick= "showDiv( 'div_current ') " height= "50 " width= "50 "> </td>
</tr>
<tr>
<td style= "width: 398px; height: 138px ">
<div id= "div_current " style= "display: block; "> div_current
<img src= "images/banner.jpg " height= "50 " width= "50 ">
</div>
</td>
<td style= "width: 398px; height: 138px ">
<div id= "div_used " style= "display: none; "> div_used
<img src= "images/4.jpg &q