大佬教程收集整理的这篇文章主要介绍了javascript – 使用JQuery显示/隐藏控件,具体取决于下拉列表选择的值,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
谢谢.
<%@ Page title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="drop_down_test.WebForm1" %>
<form runat="server" ID="frmReport"> <asp:DropDownList ID="ddlReports" OnChange="ShowHide()" AutoPostBACk="true" runat="server" onSELEctedindexchanged="ddlReports_SELEctedIndexChanged"> <asp:ListItem Text="Please SELEct Report" Value="Default" /> <asp:ListItem Text="Report 1" Value="ReportValue1" /> <asp:ListItem Text="Report 2" Value="ReportValue2" /> </asp:DropDownList> <br /> <br /> <div id="Report1Section"> <asp:Label ID="lblReport1" Text="This is for Report 1" runat="server" /> </div> <br /> <div id="Report2Section"> <asp:Label ID="lblReport2" Text="This is for Report 2" runat="server" /> </div> </form> <script language="JavaScript" type="text/javascript" src="~/Scripts/jquery-1.4.1.js"></script> <script type="text/javascript"> function ShowHide() { var ddlSELEctedIndex = ('#<%= ddlReportName.ClientID %>').get(0).SELEctedIndex; switch (ddlSELEctedIndeX) { case 1: $('#Report1Section').show('slow'); $('#Report2Section').hide('fast'); break; case 2: $('#Report1Section').hide('fast'); $('#Report2Section').show('slow'); break; } } </script>
<div id="Report2Section" class="Report2 reportDiv"> <asp:Label ID="lblReport2" Text="This is for Report 2" runat="server" /> </div>
然后使用列表项的值中的@L_450_6@(已删除的空格)来获取您需要显示的div的ID.您可以在页面的ready(…)事件中将事件连接到JQuery.
< asp:DropDownList ID =“ddlReports OnChange =”ShowHide()“runat =”server“
的AutoPostBACk = ‘真正的’
[像@SeanTaylor那样从下拉列表中取出自动回复 – 你想要改变你的javascript代码而不是ASP.Net回发到服务器机制.]
onSELEctedindexchanged = “ddlReports_SELEctedIndexChanged”
[通过nu-skool,JQuery方式(见下文)]将您的活动连接起来]
>
< asp:ListItem Text =“Report 1”Value =“Report1 [删除值中的空格] />
然后,您可以将所有reportdiv上的slideDown作为一个组调用,然后通过下拉列表中的ID调用所需的slideUp:
$(document).ready(function(){//there is a more modern way of wriTing this line. $('.ddlReports').change(function(){//JQuery style of wiring events up $('.reportDiv').slideUp();//takes care of whichever one is showing (if any). $('#' + $(this).val() + "Section").slideDown(); }); });
以上是大佬教程为你收集整理的javascript – 使用JQuery显示/隐藏控件,具体取决于下拉列表选择的值全部内容,希望文章能够帮你解决javascript – 使用JQuery显示/隐藏控件,具体取决于下拉列表选择的值所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。