ASP.NET中通过CheckBox控制TextBox的Enabled属性

来源:百度知道 编辑:UC知道 时间:2024/05/24 13:20:41
如题,我想通过CheckBox控制TextBox的Enabled属性,即当CheckBox选中时对应TextBox状态为可用,未选中为不可用。不使用CheckBox的AutoPostBack="True"属性,因为那样页面会刷新。想用JAVA脚本完成,由于小弟初学不会写,希望高手能指点迷津。谢谢

楼上的方法多余了,没必要用Ajax
我举个例子:
<from runat="server">
<p>用户名:
<asp:TextBox ID="txtUser" runat="server" />
</p>
<p>密码:
<asp:TextBox ID="txtPass" runat="server" />
</p>
<p>
<input id="chkAgree" type="radio" />我同意协议
<asp:Button ID="txtPost" Text="确定" runat="server" />
</p>
</form>
<script type="text/javascript">
onload=Change;
chkAgree.onmouseup=Change;
function Change()
{
var myStatus=! document.getElementById("chkAgree").checked;
document.getElementById('<%=txtUser.ClientID%>').disabled=myStatus;
document.getElementById('<%=txtPass.ClientID%>').disabled=myStatus;
document.getElementById('<%=txtPost.ClientID%>').disabled=myStatus;
}
</