将焦点移至特定字段 [英] Move focus to a particular field

查看:58
本文介绍了将焦点移至特定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,可以在页面上添加显示表单。如何在单击该按钮时将焦点移动到表单的第一个字段?

I have a button that will add show a form on the page. how can I move the focus to the first field of the form when that button is clicked?

简单示例:

HTML:

<form style="display:none;" id="newForm">
   <input type="text" id="firstField">
</form>
<input type="button" id="showForm" value="add new">

jQuery:

 $("#showForm").click(function(){
     $("#newForm").show();
     //move focus??
});


推荐答案

可能是这样的:

$("#newForm input:first").focus();

这篇关于将焦点移至特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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