单选按钮禁用Html.textbox
Radio button disable Html.textbox
我有两个单选按钮Billable"Y"&计费"N"。它们连接到一个值为"Y"或"N"的数据库。
如果Radio="Y",则需要禁用TextBox NonBillableReason。
如果Radio="N",则需要禁用TextBox NonBillableReason。
js。我在页面加载方面工作得很好,我根据Radio值"Y"或"N"获得正确的行为。问题是我似乎无法点击单选按钮并更改禁用、true(或)禁用、false。
<label><span>YES</span>@Html.RadioButtonFor(model => model.Billable, "Y") </label>
<label><span>NO</span>@Html.RadioButtonFor(model => model.Billable, "N")
@Html.TextBoxFor(model => model.NonBillableReason,new {@class = "form-control", @placeholder = "NOT BILLABLE BECAUS..."})
<script>
$(document).ready(function () {
if ($("#Billable:checked").val() == "Y") {
$("#NonBillableReason").attr("disabled", true);
}
if ($("#Billable:checked").val() == "N") {
$("#NonBillableReason").attr("disabled", false);
}
});
</script>
由于使用jQuery,您可以在单选按钮上添加change
事件,然后更改禁用NonBillableReason
元素:
function validate() {
if ($("#Billable:checked").val() == "Y") {
$("#NonBillableReason").attr("disabled", true);
}
if ($("#Billable:checked").val() == "N") {
$("#NonBillableReason").attr("disabled", false);
}
}
$(document).ready(function () {
validate();
$('input').change(validate);
});
尝试
if($('#radio_button').is(':checked'))
{
$("#NonBillableReason").attr("disabled", true);
}
else
{
$("#NonBillableReason").attr("disabled", false);
}
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 如何设置html元素填充的动画
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- 如何编写HTML输入的JS内联
- Dojo不解析自定义小部件的模板html中的小部件声明性
- 使用javascript将动态表从一个html页面打印到另一个html页
- 通过javascript重定向html传递php变量
- 如何使Javascript动态html表及其上的事件
- 在chrome.tabs.onCreated之后加载HTML页面
- 如何在vs2002中调试html页面
- 如何使用javascript或html下载PDF格式的填写表单
- 视频HTML没有'无法在Internet Explorer 11上工作
- HTML表单提交时未执行外部函数
- 单选按钮禁用Html.textbox
- Hidding TextBox in html
- textbox in html
- 使用java脚本将HTML输入标记转换为Dojo TextBox
- HTML.TextBox用于范围验证
- 我在html中使用了type=url,textbox正在接受http://////////,我需要它只接受两个斜杠.我该