我想动态禁用/启用文本框,然后单击复选框.我该怎么做?我正在使用这个:
@{
object addInput = (Model.AddInput) ? null : new { disabled = "disabled" };
}
@Html.CheckBoxFor(model=> model.AddInput)
@Html.TextBoxFor(model => model.Input.Name, addInput)
Run Code Online (Sandbox Code Playgroud)
但它只适用于开始.单击该复选框不会改变任何内容.如何做一些绑定来自动更改禁用状态?
这需要在javascript中完成.
@{
object addInput = (Model.AddInput) ? null : new { disabled = "disabled" };
}
@Html.CheckBoxFor(model=> model.AddInput)
@Html.TextBoxFor(model => model.Input.Name)
<script>
$('#AddInput').click(function() {
var $this = $(this);
if ($this.is(':checked')) {
$('#Name').removeAttr("disabled");
} else {
$('#Name').attr("disabled", "disabled")
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13468 次 |
| 最近记录: |