请各位大虾支个招!

isaxu 2003-03-25 10:05:37
小妹遇到一个问题:从数据库中读取电影的种类(type1类下面有N个type2),先把type1类电影的名字显示在页面上,当鼠标移动到某一个type1类电影类别上的时候,下面出现type1下type2子类的电影类别名称,鼠标移开子类二消失(类似以前微软经典导航栏),代码如下:
<?php

include "common.inc.php";

echo "<script LANGUAGE=JavaScript>\n";
echo " with (document)\n";
echo" { \n";
echo " write(\"<STYLE TYPE='text/css'>\"); \n";
echo " write(\".gen1(visibility:hidden)\"); \n";
echo " write(\"</STYLE>\"); \n";
echo " } \n";

echo "function initItq(){ \n";
echo " divColl = document.all.tags('DIV'); \n";
echo " for (i=0; i<divColl.length; i++) { \n";
echo" whichEl = divColl(i); \n";
echo " if (whichEl.className == 'gen1') whichEl.style.visibility = 'hidden'; \n";
echo " } \n";
echo " } \n";

$typeResult1=pg_exec($PG_CONN,"select * from movietype where mtype = '1';");
$count1=pg_numrows($typeResult1);
echo "count1 = " . $count1 . "; \n";
echo "var type1=new Array();\n";
for($i=0;$i<$count1;$i++)
{
$arrname1=pg_fetch_array($typeResult1,$i);
$type1[$i] = $arrname1["mname"];
echo "type1[$i] ='a" . $i . "';\n";
$tmpname1 = $arrname1["mname"];
$typeResult12=pg_exec($PG_CONN,"select * from movietype where mtype = '2' and type1 = '$tmpname1';");
$count12=pg_numrows($typeResult12);
$count2[$i] = $count12 ;
for($j=0;$j<$count12;$j++)
{
$arrname12=pg_fetch_array($typeResult12,$j);
$type2[$i][$j] = $arrname12["mname"];
}
}

//function showIt(i)
echo " function showIt(i) \n ";
echo " { \n";
echo "alert('aaa'); \n";
echo " whichE1 = eval('a' + i ); \n";
echo " whichE1.style.visibility == 'show'); \n ";
//echo "alert('aaa'); \n";
//echo "alert('whichE1.style.visibility'); \n";
echo " for(j = 0;j<count1 && j<>i;j++) \n ";
echo " { \n ";
echo " whichE1 = eval('a' + j ); \n";
echo " whichE1.style.visibility == 'hidden'); \n ";
echo " } \n ";
echo " } \n ";

//function hiddenIt()
echo " function hiddenIt() \n ";
echo " { \n";
echo " for(j = 0;j<count1;j++) \n ";
echo " { \n ";
echo " whichE1 = eval('a' + j ); \n";
echo " whichE1.style.visibility == 'hidden'); \n ";
echo " } \n ";
echo " } \n ";

echo "onload = initItq; \n";

echo "</script>";
?>

<body>
<table width="90%" border="0">
<tr>
<?php for ($i=0;$i<$count1;$i++){ ?>
<td onMouseOver="showIt('<?php echo $i;?>')"><?php echo $type1[$i];?>
<div id='<?php echo 'a'.$i;?>' class="gen1" style="position:absolute; width:113px; height:82px; z-index:1; left: 3px; top: 33px; visibility: hidden;">
<table width="90%" border="0">
<?php for ($j=0;$j<$count2[$i];$j++) { ?>
<tr><td><?php echo $type2[$i][$j];?></td></tr>
<?php } ?>
</table>
</div>
</td>
<?php } ?>
</tr>
</table>
<table width="90%" height="561" border="0">
<tr>
<td onMouseOver="hiddenIt()"> </td>
</tr>
</table>
</body>
...全文
22 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2003-03-25
  • 打赏
  • 举报
回复
没有数据如何调试?
你应该贴出浏览器中的代码。
isaxu 2003-03-25
  • 打赏
  • 举报
回复
还是不行,和原来一样的问题,缺少对象!
xuzuning 2003-03-25
  • 打赏
  • 举报
回复
太乱了,改写了一下。先试试
<?php

include "common.inc.php";

echo <<< SCRIPT
<script LANGUAGE=JavaScript>
with (document)
{
write("<STYLE TYPE='text/css'>");
write(".gen1(visibility:hidden)");
write("</STYLE>");
}

function initItq(){
divColl = document.all.tags('DIV');
for (i=0; i<divColl.length; i++) {
whichEl = divColl(i);
if (whichEl.className == 'gen1')
whichEl.style.visibility = 'hidden';
}
}
SCRIPT;

$typeResult1=pg_exec($PG_CONN,"select * from movietype where mtype = '1';");
$count1=pg_numrows($typeResult1);
echo "count1 = $count1;\n";
echo "var type1=new Array();\n";
for($i=0;$i<$count1;$i++)
{
$arrname1=pg_fetch_array($typeResult1,$i);
$type1[$i] = $arrname1["mname"];
echo "type1[$i] ='a$i';\n";
$tmpname1 = $arrname1["mname"];
$typeResult12=pg_exec($PG_CONN,"select * from movietype where mtype = '2' and type1 = '$tmpname1';");
$count12=pg_numrows($typeResult12);
$count2[$i] = $count12 ;
for($j=0;$j<$count12;$j++)
{
$arrname12=pg_fetch_array($typeResult12,$j);
$type2[$i][$j] = $arrname12["mname"];
}
}

//function showIt(i)
echo <<< SCRIPT
function showIt(i)
{
alert('aaa');
whichE1 = eval('a' + i );
whichE1.style.visibility == 'show');
for(j = 0;j<count1 && j<>i;j++)
{
whichE1 = eval('a' + j );
whichE1.style.visibility == 'hidden');
}
}

function hiddenIt()
{
for(j = 0;j<count1;j++)
{
whichE1 = eval('a' + j );
whichE1.style.visibility == 'hidden');
}
}

onload = initItq;

</script>
SCRIPT;

?>

<body>
<table width="90%" border="0">
<tr>
<?php
for ($i=0;$i<$count1;$i++){
echo <<< TD
<td onMouseOver="showIt('$i')">$type1[$i]
<div id='a$i' class="gen1" style="position:absolute; width:113px; height:82px; z-index:1; left: 3px; top: 33px; visibility: hidden;">
<table width="90%" border="0">
TD;
for ($j=0;$j<$count2[$i];$j++) {
echo "<tr><td>{$type2[$i][$j]}</td></tr>";
}
echo "
</table>
</div>
</td>";
}
?>
</tr>
</table>
<table width="90%" height="561" border="0">
<tr>
<td onMouseOver="hiddenIt()"> </td>
</tr>
</table>
</body>
isaxu 2003-03-25
  • 打赏
  • 举报
回复
为什么每次都会告诉我“缺少对象”阿?:(
isaxu 2003-03-25
  • 打赏
  • 举报
回复
已经好了谢谢!

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧