如何在复选框检查时禁用文本框是真的&反之亦然 [英] How to disable textbox on checkbox check is true & viceversa
本文介绍了如何在复选框检查时禁用文本框是真的&反之亦然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Html Helper。现在我要禁用我的文本框上的复选框是true.My View如下。
I am using Html Helper.Now i want to disable My textbox on checkbox checked is true.My View is as follows.
@using (Html.BeginForm())
{
<fieldset>
<legend>
Login
</legend>
<div>
@Html.LabelFor(m => m.user_name)
@Html.TextBoxFor(m=>m.user_name)
@Html.ValidationMessageFor(m=>m.user_name)
</div>
<div>
@Html.CheckBoxFor( m=>m.Active)
@Html.ValidationMessageFor(m=>m.Active)
</div>
如何禁用UserName文本框如果选中复选框..Plz help。
How to Disable UserName Textbox If checkbox is checked..Plz help.
推荐答案
根据你的复选框的状态,禁用文本框如下。
According to your check box's status, disable the text box is as below.
@Html.TextBoxFor(m=>m.user_name, new { @readonly="readonly" })
单击复选框时使用下面提到的 JS代码。
When click the check box use below mentioned JS code.
(#YourTextBoxId)。 removeAttr('readonly');
("#YourTextBoxId").removeAttr('readonly');
注意:在这里你必须找到文本框的ID使用chrome dev工具。
Note:Here you have to find the Id of the text box by using chrome dev tool.
参考
禁用/启用-A-文本框与 - 校验事件对的一复选框-U sing-jquery [ ^ ]
disable-enable-element-with-checkbox-and-jquery [ ^ ]
这篇关于如何在复选框检查时禁用文本框是真的&反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文