首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

100分C#加javascript做动态菜单有关问题

2012-02-29 
100分求助C#加javascript做动态菜单问题我做的这个菜单无法拉下和收起,数据都能显示出来的。请哪位大人帮我

100分求助C#加javascript做动态菜单问题
我做的这个菜单无法拉下和收起,数据都能显示出来的。请哪位大人帮我看看,谢谢了

代码如下:
//javascript--显示和隐藏下拉框的代码
string   st= " <script   language= 'javascript '> ";  
st+= " ' <!--   ' ";
st+= "var   old_menu   =   ' '; ";
st+= "var   old_cell   =   ' '; ";  
st+= "function   menuclick(   submenu   ,cellbar) ";  
st+= "{   if(   old_menu   !=   submenu   ){   if(   old_menu   != ' '   ){   old_menu.style.display   =   'none ';   old_cell.src=   'plus.gif ';   }   ";
st+= "submenu.style.display   =   'block ';   cellbar.src   =   'plus.gif ';   old_menu   =   submenu;   old_cell   =   cellbar;   } ";
st+= "else{   submenu.style.display   =   'none ';   cellbar.src=   'plus.gif ';   old_menu   =   ' ';   old_cell   =   ' ';   } ";  
st+= "}   ' ";
st+= "//--> ";

//这里是对数据进行读取
st= " <tabel     borderColor= 'lightskyblue '   cellSpacing= '0 '   cellPadding= '0 '   width= '100 '   border= '1 'align= 'center '> ";
string   str= "select   distinct(class)   from   club_class ";
DataSet   ds=SqlDB.GetDataSet(str);


for(int   i=0;i <ds.Tables[0].Rows.Count;i++)
{
if(ds.Tables[0].Rows[i][0].ToString()!= " ")
{
string   str1= "select   top   5   title   from   club_main   where   class= ' "+ds.Tables[0].Rows[i][0].ToString()+ " ' ";
DataSet   ds1=SqlDB.GetDataSet(str1);

//主菜单
st+= " <tr> <td   align= 'left '   onclick= 'menuclick(submenu "+i+ ",bar "+i+ "   ); '   style= 'CURSOR:hand '   width= '103 ' ";

st+= "bordercolordark= 'white '   bordercolorlight= 'gray '   onmouseover= 'this.style.backgroundColor= '#FFCCCC ' ";

st+= "onmouseout= 'this.style.backgroundColor= ' ' '   title= '主题列表 '> ";
st+= " <img   src= '../admin/plus.gif '   border= '0 '   id= 'bar "+i+ " '   width= '11 '   height= '11 '> <font   color= '#000000 '> ";
st+= " "+ds.Tables[0].Rows[i][0].ToString()+ " </font> ";

//下拉菜单
st+= " <tr> <td   align= 'left '   width= '143 '> <span   id= 'submenu "+i+ " '   style= 'DISPLAY:block;MARGIN-LEFT:5px '> ";
for(int   j=0;j <ds1.Tables[0].Rows.Count;j++)
{
if(ds1.Tables[0].Rows[j][0].ToString().Length> 12)
{
ds1.Tables[0].Rows[j][0]=ds1.Tables[0].Rows[j][0].ToString().Substring(0,12)+ ".. ";
}
else
{
ds1.Tables[0].Rows[j][0]=ds1.Tables[0].Rows[j][0].ToString();
}
st+= " <img   src= '../user/images/index_point.gif '   border= '0 '   width= '12 '   height= '12 '> "+ds1.Tables[0].Rows[j][0].ToString()+ " <br> ";
}

st+= " </td> </tr> ";
}



}
st+= " </tabel> ";
Label1.Text=st.ToString();

运行后IE状态提示:网页上有错误

运行后源代码如下:
<TABLE   id= "Table10 "   cellSpacing= "1 "   cellPadding= "1 "   width= "150 "   align= "center "   border= "0 ">
<TBODY>
<TR>
<TD>
<span   id= "Label1 ">
<tabel     borderColor= 'lightskyblue '   cellSpacing= '0 '   cellPadding= '0 '   width= '100 '   border= '1 'align= 'center '>
<tr>
<td   align= 'left '   onclick= 'menuclick(submenu0,bar0   ); '   style= 'CURSOR:hand '   width= '103 'bordercolordark= 'white '   bordercolorlight= 'gray '   onmouseover= 'this.style.backgroundColor= '#FFCCCC 'onmouseout= 'this.style.backgroundColor= ' ' '   title= '主题列表 '>
<img   src= '../admin/plus.gif '   border= '0 '   id= 'bar0 '   width= '11 '   height= '11 '>
<font   color= '#000000 '> 检测方法 </font>
<tr> <td   align= 'left '   width= '143 '>
<span   id= 'submenu0 '   style= 'DISPLAY:block;MARGIN-LEFT:5px '>
<img   src= '../user/images/index_point.gif '   border= '0 '   width= '12 '   height= '12 '> 中药提取物的检验 <br>
</td>
</tr>

<tr> <td   align= 'left '   onclick= 'menuclick(submenu1,bar1   ); '   style= 'CURSOR:hand '   width= '103 'bordercolordark= 'white '   bordercolorlight= 'gray '   onmouseover= 'this.style.backgroundColor= '#FFCCCC 'onmouseout= 'this.style.backgroundColor= ' ' '   title= '主题列表 '>
<img   src= '../admin/plus.gif '   border= '0 '   id= 'bar1 '   width= '11 '   height= '11 '>
<font   color= '#000000 '> 配方切磋 </font>
<tr>
<td   align= 'left '   width= '143 '>
<span   id= 'submenu1 '   style= 'DISPLAY:block;MARGIN-LEFT:5px '>
<img   src= '../user/images/index_point.gif '   border= '0 '   width= '12 '   height= '12 '> 化妆品检验技术大全 <br>
<img   src= '../user/images/index_point.gif '   border= '0 '   width= '12 '   height= '12 '> 化妆品生产新技术新工艺新.. <br>
<img   src= '../user/images/index_point.gif '   border= '0 '   width= '12 '   height= '12 '> 防晒剂,高分子量硅油的高.. <br>
<img   src= '../user/images/index_point.gif '   border= '0 '   width= '12 '   height= '12 '> 化妆品化学与工艺技术大全 <br>
<img   src= '../user/images/index_point.gif '   border= '0 '   width= '12 '   height= '12 '> 一个不辍的原料知识网 <br>
</td>
</tr>
</TR>
</TABLE>

[解决办法]
对了:把第2行
st+= " ' <!-- ' ";
改为
st+= " '// <!-- ' ";


俺直接新建了一个这样的html,直接用浏览器打开可以
<script language= 'javascript '>
// <!--
var old_menu = ' ';


var old_cell = ' ';
function menuclick( submenu ,cellbar)
{ if( old_menu != submenu ){ if( old_menu != ' ' ){ old_menu.style.display = 'none '; old_cell.src= 'plus.gif '; }
submenu.style.display = 'block '; cellbar.src = 'plus.gif '; old_menu = submenu; old_cell = cellbar; }
else{ submenu.style.display = 'none '; cellbar.src= 'plus.gif '; old_menu = ' '; old_cell = ' '; }
}
//-->
</script>
<TABLE id= "Table10 " cellSpacing= "1 " cellPadding= "1 " width= "150 " align= "center " border= "0 ">
<TBODY>
<TR>
<TD>
<span id= "Label1 ">
<tabel borderColor= 'lightskyblue ' cellSpacing= '0 ' cellPadding= '0 ' width= '100 ' border= '1 'align= 'center '>
<tr>
<td align= 'left ' onclick= 'menuclick(submenu0,bar0 ); ' style= 'CURSOR:hand ' width= '103 'bordercolordark= 'white ' bordercolorlight= 'gray ' onmouseover= 'this.style.backgroundColor= '#FFCCCC 'onmouseout= 'this.style.backgroundColor= ' ' ' title= '主题列表 '>
<img src= '../admin/plus.gif ' border= '0 ' id= 'bar0 ' width= '11 ' height= '11 '>
<font color= '#000000 '> 检测方法 </font>
<tr> <td align= 'left ' width= '143 '>
<span id= 'submenu0 ' style= 'DISPLAY:block;MARGIN-LEFT:5px '>
<img src= '../user/images/index_point.gif ' border= '0 ' width= '12 ' height= '12 '> 中药提取物的检验 <br>
</td>
</tr>

<tr> <td align= 'left ' onclick= 'menuclick(submenu1,bar1 ); ' style= 'CURSOR:hand ' width= '103 'bordercolordark= 'white ' bordercolorlight= 'gray ' onmouseover= 'this.style.backgroundColor= '#FFCCCC 'onmouseout= 'this.style.backgroundColor= ' ' ' title= '主题列表 '>
<img src= '../admin/plus.gif ' border= '0 ' id= 'bar1 ' width= '11 ' height= '11 '>
<font color= '#000000 '> 配方切磋 </font>
<tr>
<td align= 'left ' width= '143 '>
<span id= 'submenu1 ' style= 'DISPLAY:block;MARGIN-LEFT:5px '>
<img src= '../user/images/index_point.gif ' border= '0 ' width= '12 ' height= '12 '> 化妆品检验技术大全 <br>
<img src= '../user/images/index_point.gif ' border= '0 ' width= '12 ' height= '12 '> 化妆品生产新技术新工艺新.. <br>
<img src= '../user/images/index_point.gif ' border= '0 ' width= '12 ' height= '12 '> 防晒剂,高分子量硅油的高.. <br>
<img src= '../user/images/index_point.gif ' border= '0 ' width= '12 ' height= '12 '> 化妆品化学与工艺技术大全 <br>
<img src= '../user/images/index_point.gif ' border= '0 ' width= '12 ' height= '12 '> 一个不辍的原料知识网 <br>
</td>
</tr>
</TR>
</TABLE>
[解决办法]
string st= " <script language= 'javascript '> ";
st+= " ' <!-- ' "; --不知道是不是应该去掉单引号
st+= "var old_menu = ' '; ";
st+= "var old_cell = ' '; ";
st+= "function menuclick( submenu ,cellbar) ";
st+= "{ if( old_menu != submenu ){ if( old_menu != ' ' ){ old_menu.style.display = 'none '; old_cell.src= 'plus.gif '; } ";


st+= "submenu.style.display = 'block '; cellbar.src = 'plus.gif '; old_menu = submenu; old_cell = cellbar; } ";
st+= "else{ submenu.style.display = 'none '; cellbar.src= 'plus.gif '; old_menu = ' '; old_cell = ' '; } ";
st+= "} ' "; --单引号
st+= "//--> ";---没有 </script>

热点排行
Bad Request.