专注于在飞行中创建的元素 [英] focus an element created on the fly

查看:110
本文介绍了专注于在飞行中创建的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何集中一个在飞行中创建的元素?

how to focus an element created on the fly?

推荐答案

只需调用 .focus() ,例如:

Just call .focus() on the element after it's added to the DOM, for example:

var input = document.createElement("input"); //create it
document.body.appendChild(input);            //append it
input.focus();                               //focus it

你可以在这里测试

这篇关于专注于在飞行中创建的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆