gpt4 book ai didi

Javascript 更改 asp :textbox visible property to true

转载 作者:太空宇宙 更新时间:2023-11-03 16:12:05 25 4
gpt4 key购买 nike

我正在尝试创建一个表单,其中应根据下拉列表显示或隐藏文本框,如果仅显示文本框,还要验证文本框。

有人可以帮我吗?

<asp:DropDownList 
ID="txt_days"
CssClass="txt_drpbx"
runat="server"
siz="10"
>
<asp:ListItem Text="Select" Value="0"></asp:ListItem>
<asp:ListItem Text="1" Value="1"></asp:ListItem>
<asp:ListItem Text="2" Value="2"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator6"
runat="server"
ControlToValidate="txt_days"
ForeColor="Red"
ErrorMessage="Please Select No of days on leave"
InitialValue="0"
ValidationGroup="fdbk_chk"
>*</asp:RequiredFieldValidator>
<asp:TextBox
ID="txt_todate"
runat="server"
ReadOnly="true"
Visible="false"
CssClass="txt_bx"
></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="txt_todate"
ForeColor="Red"
ErrorMessage="Please Select Feedback Given For"
ValidationGroup="fdbk_chk"
>*</asp:RequiredFieldValidator>
<asp:Button
ID="btn_submit"
Text="Submit"
CssClass="btn_button"
runat="server"
onclick="btn_submit_Click"
ValidationGroup="fdbk_chk"
/>
<asp:ValidationSummary
ID="ValidationSummary1"
runat="server"
HeaderText="Some fields are missing"
ShowMessageBox="True"
ShowSummary="False"
ValidationGroup="fdbk_chk"
/>

最佳答案

试试这个:

<script>

function ShowHideTextBox(ddlId)
{
var ddl = document.getElementById(ddlId.id);

if(ddl.value == 1) //your condition
{
document.getElementById('txt_todate').style.display = 'none';
}
else
{
document.getElementById('txt_todate').style.display = '';

}
}

<asp:DropDownList ID="txt_days" CssClass="txt_drpbx" runat="server"  siz="10" onchange="ShowHideTextBox(this);" 

<asp:TextBox ID="txt_todate" runat="server" ReadOnly="true" Visible="false" CssClass="txt_bx"></asp:TextBox>

关于Javascript 更改 asp :textbox visible property to true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17102290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com