选中/取消选中复选框时启用/禁用文本框 [英] Enable/Disable TextBox when Check/Uncheck Checkbox

查看:147
本文介绍了选中/取消选中复选框时启用/禁用文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在用C#开发的项目中有一个需求.
我想基于选中/取消选中ASP:Checkbox启用/禁用一个asp.textbox.

请让我知道如何实现它(最好的方法)?

谢谢

Hi
I have a requirement in my project which is being developed in C#.
I would like to enable/disable one asp.textbox based on the checking/Unchecking ASP:Checkbox.

Kindly let me know how to implement it (best way)?

Thanks

推荐答案

您可以使用javascript进行操作,也可以在复选框上使用onCheckChanged事件,然后在后面的代码中处理禁用文本框的操作.我不仅会为此提供代码,因为这是非常基本的事情.试试看,如果您遇到编码问题,请更新您的问题,我们将为您提供进一步的帮助.
You can either do it using javascript, or you can use the onCheckChanged event on the checkbox and then handle the disabling of the textbox in the code-behind. I won''t just give you the code for this as it is a very basic thing. Try it out and if you run into coding issues, update your question and we can help further.


最好,最好的方法是仅在客户端执行此操作(这是可以接受;即使用户在浏览器中关闭了脚本,某些站点也需要执行),因为这种简单操作的回发可能会花费大量时间才是合理的.也就是说,您可以使用JavaScript来完成;这样做的一种便捷方法是使用jQuery.

要启用/禁用,可以使用以下命令:
I thing, the best way would be doing it on the client side only (it this is acceptable; some sites are required to perform even it the user switched scripting off in the browser), because the postback for this simple operation would might take to much time to be reasonable. That said, you could do it in JavaScript; and one convenient way of doing it would be using jQuery.

To enable/disable, you can use this:
//enable:


(' #myTextBoxId').removeAttr(' 已禁用'); // 禁用:
('#myTextBoxId').removeAttr('disabled'); //disable:


这篇关于选中/取消选中复选框时启用/禁用文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆