【问题标题】:Jquery - Enable an editorFor text field on button clickJquery - 在按钮单击时启用 editorFor 文本字段
【发布时间】:2020-10-20 03:45:41
【问题描述】:

我有一个 editorFor 开始禁用,看起来像这样

 @Html.EditorFor(job => j.serialNumber, new { htmlAttributes = new { @class = "form-control", disabled = true} })

然后在下面我有一个看起来像这样的编辑按钮

<input id="edit@(j.serialNumber)" type="button" class="noprint btn btn-primary" value="Edit" onclick="enableEdit('@(j.serialNumber)')" />     

这会调用我当前看起来像这样的 enableEdit 方法

 function enableEdit(serialNumber) {
       
  }

为了启用“EditorFor”文本框,我必须在方法中添加什么?

【问题讨论】:

  • 你能显示为@Html.EditorFor(job =.. 生成的html代码吗?

标签: javascript c# jquery asp.net-mvc razor


【解决方案1】:

你可以这样设置EditorFor元素的id:

@Html.EditorFor(job => j.serialNumber, new { htmlAttributes = new { @class = "form-control", @id = "my-editor", disabled = true} })

然后,在您的方法中,您可以通过 jquery 选择它并设置 disabled 属性。

$("#my-editor").prop("disabled", false);

https://learn.jquery.com/using-jquery-core/faq/how-do-i-disable-enable-a-form-element/

【讨论】:

    猜你喜欢
    • 2012-05-23
    • 1970-01-01
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 2019-06-10
    相关资源
    最近更新 更多