【问题标题】:How to write javascript onfocusout/onblue event for @Html.EditorFor in mvc application如何在 mvc 应用程序中为 @Html.EditorFor 编写 javascript onfocusout/onblur 事件
【发布时间】:2020-12-01 16:49:45
【问题描述】:

我的代码看起来像

 <div class="col-4">@Html.LabelFor(m => m.Password)</div>
                <div class="col-8">
                    @Html.EditorFor(m => m.Password)
                    @Html.ValidationMessageFor(m => m.Password)
 </div>

我在我的应用程序中使用 Javascript。

如何将 onfoucsout/onblue 事件写入我的密码文本框?

【问题讨论】:

  • 嗨@Sareka Avinash,如果我的解决方案对您有用,您能否接受它作为答案,非常感谢!

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


【解决方案1】:

你可以尝试如下:

<div class="col-8">
    @Html.EditorFor(m => m.Password, new { htmlAttributes = new { onblur = "OnBlurEvent()" } })
    @Html.ValidationMessageFor(m => m.Password)
</div>

@section scripts{
    <script type="text/javascript">
        function OnBlurEvent() {
            alert("Hello!");
        }
    </script>
}

或者使用匿名函数

@section scripts{
    <script type="text/javascript">
        $('#Password').blur(function(){
            alert("Hello!");
        });
    </script>
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    • 2022-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多