简体   繁体   English

如何在cshtml中的$(document).ready(function()内使用if条件?

[英]how to use if condition inside $(document).ready(function() in cshtml?

trying to disable two html.Textboxfor field on condition.Not working .Looks like syntax issue. 试图在条件上禁用两个html.Textboxfor字段。不起作用。看起来像语法问题。

$(document).ready(function() {

        if (Model.Key == Guid.Empty) {
            $("#@idPasswordTextBox").attr('disabled', 'disabled');
            $("#@idConfirmPasswordTextBox").attr('disabled', 'disabled');
        }

});

Is that a way to use if condition inside $(document).ready(function() {} ? 这是$(document).ready(function() {} if条件使用的一种方法吗?

Try wrapping your razor code in ( ) 尝试将剃刀代码包装在()中

if (Model.Key == Guid.Empty) {
        $("#@(idPasswordTextBox)").attr('disabled', 'disabled');
        $("#@(idConfirmPasswordTextBox)").attr('disabled', 'disabled');
    }

should escape the javascript string 应该转义javascript字符串

@if(Model.Key == Guid.Empty) {
    <text>$("#idPasswordTextBox").attr('disabled', 'disabled');</text>
}

remove @ from your selector, or use double @@ 从选择器中删除@ ,或使用双@@

@if(Model.Key == Guid.Empty) {
    <text>$("#@@idPasswordTextBox").attr('disabled', 'disabled');</text>
}

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

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