折叠面板 JavaScript 问题
我有一个可折叠面板扩展器。 我对扩展器没有任何问题。 但是,我有一个打开面板的链接,我想要另一个链接说折叠以关闭它。 我想隐藏一个显示一个javascript端。 问题是它只适用于第一行,但不适用于其他行,因为我没有获得唯一的 ID 或其他东西。 我还没有找到合法的答案。 我尝试过通过获取父元素来使用jquery,但没有成功。 我能做些什么?
答案:
<asp:TemplateField HeaderText="Lng Descr" SortExpression="LongDescription">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("LongDescription") %>' TextMode ="MultiLine" Rows="5" ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<table>
<tr id="expand" style="display:">
<td>
<asp:Label ID="Label3" runat="server" ForeColor="Blue"><u></u></asp:Label>
</td>
</tr>
</table>
<asp:Panel ID="Panel1" runat="server" >
<table>
<tr>
<td>
<%#Eval("LongDescription")%>
</td>
</tr>
</table>
</asp:Panel>
<ajaxToolkit:CollapsiblePanelExtender ID="cpe" runat="Server"
TargetControlID = "Panel1"
CollapsedSize="0"
ExpandedSize="50"
Collapsed="true"
ExpandControlID="Label3"
CollapseControlID="Label3"
AutoCollapse="false"
Scrollcontents="false"
collapsedText="<u>Expand"
ExpandDirection="Vertical"
ExpandedText = "<u>Collapse"
TextLabelID="Label3" />
</ItemTemplate>
</asp:TemplateField>
I have a collapsible panel extender. I have no issues with the extender. however, I have a link that opens the panel and I want another link saying collapse to close it. I want to hide one show one javascript side. The issue is that it only works for the first row but not the others because I am not getting the unique ID or something. I haven't found a legitimate answer yet. I've tried jquery by getting parent elements and I was unsuccessful. What can I do?
Answer:
<asp:TemplateField HeaderText="Lng Descr" SortExpression="LongDescription">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("LongDescription") %>' TextMode ="MultiLine" Rows="5" ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<table>
<tr id="expand" style="display:">
<td>
<asp:Label ID="Label3" runat="server" ForeColor="Blue"><u></u></asp:Label>
</td>
</tr>
</table>
<asp:Panel ID="Panel1" runat="server" >
<table>
<tr>
<td>
<%#Eval("LongDescription")%>
</td>
</tr>
</table>
</asp:Panel>
<ajaxToolkit:CollapsiblePanelExtender ID="cpe" runat="Server"
TargetControlID = "Panel1"
CollapsedSize="0"
ExpandedSize="50"
Collapsed="true"
ExpandControlID="Label3"
CollapseControlID="Label3"
AutoCollapse="false"
Scrollcontents="false"
collapsedText="<u>Expand"
ExpandDirection="Vertical"
ExpandedText = "<u>Collapse"
TextLabelID="Label3" />
</ItemTemplate>
</asp:TemplateField>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 jQuery 可以轻松完成此操作。 在您的面板中,声明一个 cssclass,例如“panel”,并在标签上声明一个 css class,例如“toggle”。 您的 jQuery 将是:
您也可以放弃 ajax 工具箱控件。 当然,您还必须在 CSS 中将 .panel 声明为
display: none;
。 另请注意,您可能必须删除标签周围的表格才能有效地使用“下一个”功能。 您还只需要一个标签来来回更改其文本:编辑
这是我用来为您运行此程序的确切代码。 请注意,我通常会将脚本和 CSS 取出并将它们放入单独的文件中,但出于所有意图和目的,这是可行的(如果您使用的是 1.3.2 jquery 文件):
This is very easily done with jQuery. In your panel, declare a cssclass, say "panel", and on your label declare a css class, say "toggle". Your jQuery would be:
You can ditch the ajax toolbox control, too. Of course, you also must declare .panel to
display: none;
in your CSS. Also note, you may have to get rid of your tables around your labels for this to effectively use the "next" function. You also only need one label that will change its text back and forth:EDIT
Here's the exact code I used to get this running for you. Note that I would normally pull the script and CSS out and put them in a separate file, but for all intents and purposes, this works (if you are using the 1.3.2 jquery file):
我使用此页面中的示例成功折叠了:
http://roshanbh.com.np/2008/ 03/expandable-collapsible-toggle-pane-jquery.html
我只使用
CSS。
这是我的脚本中的内容。
I had success with collapsing using the example from this page:
http://roshanbh.com.np/2008/03/expandable-collapsible-toggle-pane-jquery.html
I just use
For the CSS.
And here is what is in my script.