【发布时间】:2020-05-23 10:23:01
【问题描述】:
在 Blazor 的早期版本中,有一个带有 selectionStart 和 selectionEnd 属性的 IHtmlInputElement 接口。
谁能解释我如何使用这些从 C# 中的文本输入控件中获取选定的文本?
更新 这是我目前所拥有的。
@page "/selectedtext"
@inject IJSRuntime JsRuntime
<h3>TextSelection</h3>
<input type="text" placeholder="Type here" @ref="myTextInput"/>
<button class="btn btn-primary" @onclick="@(async () => await GetSelectionStart(myTextInput))"></button>
@code {
public ElementReference myTextInput { get; set; }
public async Task GetSelectionStart(ElementReference element)
{
int pos = await JsRuntime.InvokeAsync<int>("GetSelectedStart", element);
}
}
// myscript.js
{
getSelectedStart : function (element) {
return element.selectionStart;
}
}
【问题讨论】: