How to set the focus to an InputText element?

前端 未结 5 535
灰色年华
灰色年华 2021-01-12 17:21

Using the example from the Microsoft docs, I\'m trying to programmatically set the focus to an input element.

Unfortunately, the example uses a standard

5条回答
  •  温柔的废话
    2021-01-12 18:04

    In .NET5 it will be much simpler:

    
    
    

    NOTE: this feature was introduced in .NET5 Preview 8 so might change until the final release!

    Also worth mentioning that in .NET5 RC1 JavaScript isolation was introduced via JS Module export/import. So if you still need to use JS interop do not pollute window object.

    Update: .NET 5 was released and this feature works unchanged.

    Also found a cool Nuget package which can do some convenient JS tricks for you e.g.: focusing previously active element without having a @ref to it. See docs here.

提交回复
热议问题