프로그래밍/Blazor

Blazor Input값 바로 받는법

JusticeD 2021. 1. 19. 12:49

.razor 에서

<input id="htmlID" type="text" @onkeyup="Print">

 

@code

{

    string result = string.Empty;

    public async void Print()
    {
        result = await JS.InvokeAsync<string>("JsFunctions.printInput", "htmlID");
    }

}

 

.js 에서

window.JsFunctions = {
    printInput: function (id) {
        var e = document.getElementById(id);
        return e.value;
    },

}