简体   繁体   中英

How to write javascript onfocusout/onblue event for @Html.EditorFor in mvc application

My code looks like

 <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>

I am using Javascript in my application.

How to write onfoucsout/onblue event to my Password textbox?

You can try like below:

<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>
}

Or use Anonymous Function

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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