我正在尝试 Microsoft 的待办事项列表示例:https ://docs.microsoft.com/en-us/aspnet/core/tutorials/build-a-blazor-app?view=aspnetcore- 3.1
我想添加一个待办事项,而不是用鼠标点击按下按钮,我想按下回车键。我对在这个解决方案中使用 JS 不满意:How to set the focus to an InputText element? 我尝试通过这行代码触发方法 private void Enter(KeyboardEventArgs e):
<button @onclick="AddTodo" @onkeypress="@(e=>Enter(e)" tabindex="0" >Add todo</button>
Run Code Online (Sandbox Code Playgroud)
它没有用。
enter code here
<input placeholder="Something todo" @bind="newTodo" />
<button @onclick="AddTodo" @onkeypress="Enter" tabindex="0" >Add todo</button>
@code {
private IList<TodoItem> todos = new List<TodoItem>();
private string newTodo;
private void AddTodo()
{
if (!string.IsNullOrWhiteSpace(newTodo))
{
todos.Add(new TodoItem { Title = newTodo });
newTodo = string.Empty;
}
}
//private void Enter(KeyboardEventArgs e)
private void …
Run Code Online (Sandbox Code Playgroud) 问题: 过去我已经能够在 Javascript 中使用 SetimeOut 函数制作动画。这是一个球落下的代码:
var ball = <HTMLElement>document.getElementById("ball");
ball.setAttribute("style", "fill:blue");
var inc2: number = 0;
var timet = document.getElementById("timeT");
timet.setAttribute("y", "420");
//time=200 ms // 1m is 3780 pixel // 400 pixels are 2m / ball is falling from 2m // g=10m/s
fallt2();
var timet2 = document.getElementById("timeT2");
timet2.setAttribute("y", "440");
var tiem = new Date();
var mili = tiem.getMilliseconds();
var dated = Date.now();
function fallt2() {
//while (inc2 <= 400) {
let ii = 0; //200 ms in 8 then …
Run Code Online (Sandbox Code Playgroud)