Javascript 在ModalPopupXtender中更改表单字段可见性
想知道是否有一种方法可以根据DropDownList的值更改来更改ModalPopup(来自ModalPopupXtender)中表单字段的可见性。此页面的技术似乎不起作用: Javascript:Javascript 在ModalPopupXtender中更改表单字段可见性,javascript,asp.net,field,visibility,modalpopupextender,Javascript,Asp.net,Field,Visibility,Modalpopupextender,想知道是否有一种方法可以根据DropDownList的值更改来更改ModalPopup(来自ModalPopupXtender)中表单字段的可见性。此页面的技术似乎不起作用: Javascript: <script type="text/javascript"> function ShowHide() { if(document.getElementById('<%=DdlASVisibilityTest.ClientID%>') == "Show
<script type="text/javascript">
function ShowHide() {
if(document.getElementById('<%=DdlASVisibilityTest.ClientID%>') == "Show") {
document.getElementById('<%=LblASBillingName.ClientID%>').style.display = 'inherit';
document.getElementById('<%=TxtASBillingName.ClientID%>').style.display = 'inherit';
}
if(document.getElementById('<%=DdlASVisibilityTest.ClientID%>') == "Hide") {
document.getElementById('<%=LblASBillingName.ClientID%>').style.display = 'none';
document.getElementById('<%=TxtASBillingName.ClientID%>').style.display = 'none';
}
{
</script>
函数ShowHide(){
if(document.getElementById(“”)=“Show”){
document.getElementById(“”).style.display='inherit';
document.getElementById(“”).style.display='inherit';
}
if(document.getElementById(“”)=“隐藏”){
document.getElementById(“”).style.display='none';
document.getElementById(“”).style.display='none';
}
{
asp.net:
<asp:ModalPopupExtender OKControlID="BtnASOkay" CancelControlID="BtnASCancel" BackgroundCssClass="modalBackground" DropShadow="True" ID="BtnAddSupplier_ModalPopupExtender" runat="server" DynamicServicePath="" Enabled="True" TargetControlID="BtnAddSupplier" PopupControlID="PnlAddSupplier">
<Animations>
<OnShown>
<FadeIn Duration="0.25" Fps="40" />
</OnShown>
<OnHiding>
<FadeOut Duration="0.25" Fps="40" />
</OnHiding>
</Animations>
</asp:ModalPopupExtender>
<asp:RoundedCornersExtender ID="RCE" runat="server" TargetControlID="PnlAddSupplier" Radius="6" Corners="All" />
<asp:Button ID="BtnAddSupplier" runat="server" CssClass="buttonsmall" Text="Add Suplier" />
<asp:Panel ID="PnlAddSupplier" CssClass ="panel" runat="server">
<div class="ASHeader">
<asp:Label ID="LblASHeader" runat="server" Text="Add Supplier" CssClass="bodytxt" Font-Bold="True"></asp:Label>
</div>
<div class="ASInputs">
<asp:Table runat="server">
<asp:TableRow ID="TRASVisibilityTest" runat="server">
<asp:TableCell ID="TCLblASVisibilityTest" runat="server"><asp:Label ID="LblASVisibilityTest" runat="server" Text="Test Visibility" CssClass="bodytxt" Font-Bold="False"></asp:Label></asp:TableCell>
<asp:TableCell ID="TCDdlASVisibilityTest" runat="server"><asp:DropDownList ID="DdlASVisibilityTest" runat="server" onchange="ShowHide()">
<asp:ListItem>Show</asp:ListItem>
<asp:ListItem>Hide</asp:ListItem>
</asp:DropDownList></asp:TableCell>
</asp:TableRow>
<asp:TableRow ID="TRASBillingName" runat="server">
<asp:TableCell ID="TCLblASBillingName" runat="server"><asp:Label ID="LblASBillingName" runat="server" Text="Supplier's Billing Name" CssClass="bodytxt" Font-Bold="False" style="display: none;"></asp:Label></asp:TableCell>
<asp:TableCell ID="TCTxtASBillingName" runat="server"><asp:TextBox ID="TxtASBillingName" CssClass="bodytxt" runat="server" style="display: none;"></asp:TextBox></asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
<div class="DivASControls" align="center">
<asp:Button ID="BtnASOkay" runat="server" CssClass="buttonsmall" Text="Add Supplier" style="display: none;" />
<asp:Button ID="BtnASCancel" runat="server" CssClass="buttonsmall" Text="Cancel" />
</div>
</asp:Panel>
显示
隐藏
非常感谢!看起来您没有正确检查下拉列表的值/文本。相反,您正在将控件本身与“显示”或“隐藏”的值进行比较。请尝试将代码更改为此,看看是否有帮助:
<script type="text/javascript">
function ShowHide()
{
var visibilityElem = document.getElementById('<%=DdlASVisibilityTest.ClientID%>');
var visibilityElemText = visibilityElem.options[visibilityElem.selectedIndex].text;
var display = (visibilityElemText == 'Show') ? 'inherit' : 'none';
document.getElementById('<%=LblASBillingName.ClientID%>').style.display = display;
document.getElementById('<%=TxtASBillingName.ClientID%>').style.display = display;
}
</script>
函数ShowHide()
{
var visibilityElem=document.getElementById(“”);
var visibilityElemText=visibilityElem.options[visibilityElem.selectedIndex].text;
变量显示=(visibilityElemText==“显示”)?“继承”:“无”;
document.getElementById(“”).style.display=display;
document.getElementById(“”).style.display=display;
}