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

高分求解ASP.NET中使用javascript遇到的麻烦,该怎么解决

2012-01-18 
高分求解ASP.NET中使用javascript遇到的麻烦我尝试做了个网站,里面有查看新闻的功能。现在我想在页面的左端

高分求解ASP.NET中使用javascript遇到的麻烦
我尝试做了个网站,里面有查看新闻的功能。现在我想在页面的左端显示新闻的标题,当鼠标停留在相应的标题行上时,右端显示该新闻的摘要。显示新闻标题和摘要的代码如下:
<div   class= "newsTitleBox ">
<div   style= "margin-top:10px; ">
<asp:GridView   ID= "GridView2 "   runat= "server "   AutoGenerateColumns= "False "   CellPadding= "4 "   ForeColor= "#333333 "   GridLines= "None "   ShowHeader= "False ">
<FooterStyle   BackColor= "#507CD1 "   Font-Bold= "True "   ForeColor= "White "   />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div   id= ' <%#   Eval( "id ")   %> '   onmousemove= "showNews(this); ">
<asp:Label   ID= "Label4 "   runat= "server "   Text= ' <%#   Eval( "title ")   %> '> </asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle   BackColor= "#EFF3FB "   />
<EditRowStyle   BackColor= "#2461BF "   />
<SelectedRowStyle   BackColor= "#D1DDF1 "   Font-Bold= "True "   ForeColor= "#333333 "   />
<PagerStyle   BackColor= "#2461BF "   ForeColor= "White "   HorizontalAlign= "Center "   />
<HeaderStyle   BackColor= "#507CD1 "   Font-Bold= "True "   ForeColor= "White "   />
<AlternatingRowStyle   BackColor= "White "   />
</asp:GridView>
</div>
</div>

//上面代码是左端新闻的标题部分

//下面代码是右端新闻的摘要部分

//两个部分的DIV的id都绑定到数据库中新闻的id字段,这个字段是自增的

//我想通过设置摘要部分的DIV的style属性来实现是否显示摘要

<div   class= "newsContentsBox ">
<asp:GridView   ID= "GridView3 "   runat= "server "   AutoGenerateColumns= "False "   ShowHeader= "False ">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<div   id= ' <%#   Eval( "id ")   %> '   style= "display:none ">
<div   class= "newsContentTitle ">
<asp:HyperLink   ID= "HyperLink2 "   runat= "server "   Text= ' <%#   Eval( "title ")   %> '> </asp:HyperLink> </div>
<div   class= "newsContent ">
<asp:Label   ID= "Label6 "   runat= "server "   Text= ' <%#   Eval( "summary ")   %> '> </asp:Label>
</div>
<span   class= "moreNews "> <img   src= "img/more.gif "   /> </span>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
我现在想在JS的showNews()里面写判断代码,当鼠标停留在某个标题行时显示相应的新闻摘要,大概的代码为:
for(...)
{
DIVTitle   =   document.getElementById();
DIVSummary   =   document.getElementById();
if(DIVTitle.id   !=   DIVSummary.id)
{

DIVSummary.style.display   =   "none ";
}
else
{
DIVSummary.style.display   =   "block ";
}
}
但具体怎么写我不清楚,我对JS了解的很少,请大家帮帮忙。谢谢

------解决方案--------------------


不懂 帮你顶下
[解决办法]
不需要这样做吧!
你这样要产生很多繁冗的代码
右边显示摘要的,做成静态的就可以了。
只要左边一个GridView 就可以了
大概代码:
<asp:TemplateField>
<ItemTemplate>
<div id= 'title_ <%# Eval( "id ") %> ' onmousemove= "__showsummary( '_ <%# Eval( "id ") %> '); ">
<asp:Label ID= "Label4 " runat= "server " Text= ' <%# Eval( "title ") %> '> </asp:Label>
</div>
<div id= 'summary_ <%# Eval( "id ") %> ' style= "display:none; ">
<asp:Label ID= "Label5 " runat= "server " Text= ' <%# Eval( "summary ") %> '> </asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
js:
function __showsummary(id){
var _base_title = document.getElementById( "title_ "+id);//要显示的信息的标题容器
var _base_summary = document.getElementById( "summary_ "+id);//要显示的信息的摘要容器

var _show_title = document.getElementById( "showtitle ");//右边标题显示容器
var _show_summary = document.getElementById( "showsummary ");//右边标题显示容器

_show_title.innerHTML = _base_title.innerHTML;
_show_summary.innerHTML = _base_summary.innerHTML;


}
[解决办法]
我用的方法,你参考一下,把你摘要字段放上去
http://blog.csdn.net/sendling/archive/2007/03/27/1543300.aspx

热点排行