更新时间:2023-01-12 18:33:56
没有其他方法可以执行此操作...您可以使用JSInterop来执行此操作,如下所示:
There is no other way to do it... You can use JSInterop to do this, as follows:
<input type="text" @ref="myref"/>
@code {
private ElementReference myref;
[Inject] IJSRuntime JSRuntime { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await
JSRuntime.InvokeVoidAsync("exampleJsFunctions.focusElement", myref);
}
}
}
<script>
window.exampleJsFunctions =
{
focusElement: function (element) {
element.focus();
}
};
</script>
希望这对您有帮助...
Hope this helps...