简体   繁体   English

如何在ASP MVC中禁用JavaScript的EditorFor

[英]How to disable an EditorFor with JavaScript in ASP MVC

I want to disable any editorfor with javascript, I try this but it's not worked : 我想用javascript禁用任何编辑器,我试试这个但是它不起作用:

<body onload="charge()">
    <div class="editor-field">
       <%: Html.EditorFor(model => model.Num_Serie, new { @id = "nn" })%>        
    </div>
</body>

and the javascript code : 和JavaScript代码:

<script type="text/javascript">

        function charge() {

            var nn = document.getElementById('nn');

            nn.disabled = 'disabled';

        }

    </script> 
document.getElementById("nn").disabled = true;

EditorFor is not rendered into one HTML element, rather it is a collection of inputs. EditorFor不会呈现为一个HTML元素,而是一个输入集合。 Therefore you should disable all of them: 因此,您应该禁用所有这些:

function charge() {
    var inputs = $('div.editor-field :input');
    inputs.attr('disabled', 'disabled');
}

for this particular case, this jQuery code will work. 对于这种特殊情况,这个jQuery代码将起作用。 $('#nn').attr('disabled','disabled');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM